filipo has asked for the wisdom of the Perl Monks concerning the following question:

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 -

Replies are listed 'Best First'.
Re: Graph modules
by choroba (Cardinal) on Aug 29, 2013 at 13:00 UTC
    Have you searched the Graph documentation for words "betweenness" and "clustering"? It seems the very module you already use provides all you need.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Hi, thanks for the message but there is nothing related to betweenness and clustering in the graph documentation.

        Hi, thanks for the message but there is nothing related to betweenness and clustering in the graph documentation.

        That statement is trivially false: Graph.pod ... CTRL-F ... "clust"