Hi Monks, there are a number of perl modules for dealing with graph data structures. I'm trying to calculate 'betweeness centrality' for a particular node P where this is the number of times shortest paths between pairs of nodes on a graph pass through node P.

I've tried to do this by calculating shortest paths between each pair of nodes but have the problem that implementations of shortest path algorithms will only return one path where there are multiple shortest paths of the same length. I need all shortest paths. For example, there a 2 paths of length 3 between nodes 1 and 4 in the following example. This bit of code will only return one of them

#!/usr/bin/perl use Boost::Graph; my $graph = new Boost::Graph(directed=>0, net_name=>'Graph Name', net_ +id=>1000); # add edges $graph->add_edge(node1=>'1', node2=>'2', weight=>1); $graph->add_edge(node1=>'1', node2=>'3', weight=>1); $graph->add_edge(node1=>'2', node2=>'4', weight=>1); $graph->add_edge(node1=>'3', node2=>'4', weight=>1); my $path=$graph->dijkstra_shortest_path('1','4'); print @{$path->{'path'}};
Anybody have any ideas?
cheers
ps
Algorithm::SocialNetwork won't install so this is out.

In reply to Graph modules by nosbod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.