Hi,

Does anyone know if there are Graph perl modules for or how to calculate betweenness centrality and clustering coefficient? I have a graph and i have its shortest path see code and output below. The next step is to calculate the betweenness and clustering coefficient.

thanks

#!/usr/bin/perl -w use Graph; #creting graph for betweenness analysis. Eg from Fig 7 netwerk analyze +r. open (OUT, ">btwn_g_OUTPUT.txt") || die $!; use Graph::Directed; my $g = Graph::Directed->new(); $g->add_edges(qw(a b b c b d c e d e )); print OUT $g; print "Graph: $g\n"; my $APSP = $g->APSP_Floyd_Warshall; #print $APSP; print " "; foreach my $v ($APSP->vertices ) { printf "%-9s ", "$v"; } print "\n"; foreach my $u ($APSP-> vertices ) { print "$u: "; foreach my $v ( $APSP->vertices ) { my $w = $APSP->path_length($u, $v); # in older version written as my $w = $APSP->get_attribute("we +ight", $u, $v); if ($w) { my @p = $APSP->path_vertices($u, $v); #in older version written as my $p = $APSP->get_attribute( +"path", $u, $v); printf "(%-5s)=%d ", "@p", $w; } else { printf "%-9s ", "-" } } print "\n" } ### calculating BFS, breath first search. use Graph::Traversal::BFS; my $b = Graph::Traversal::BFS->new($g); print "BFS: ", $b->bfs,"\n";
OUTPUT: Graph with 5 nodes : a-b,b-c,b-d,c-e,d-e c b a e d c: - - - (c e )=1 - b: (b c )=1 - - (b d e)=2 (b d )=1 a: (a b c)=2 (a b )=1 - (a b d e)=3 (a b d)=2 e: - - - - - d: - - - (d e )=1 -

In reply to Graph modules by filipo

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.