line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::NewmanGirvan;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20923
|
use 5.010000;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
12
|
use warnings;
|
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
5
|
use List::Util 'sum';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
600
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter;
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
13
|
|
|
|
|
|
|
newman_girvan
|
14
|
|
|
|
|
|
|
newman_girvan_r
|
15
|
|
|
|
|
|
|
) ] );
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw(
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
);
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.3';
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
require XSLoader;
|
26
|
|
|
|
|
|
|
XSLoader::load('Graph::NewmanGirvan', $VERSION);
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub newman_girvan {
|
29
|
0
|
|
|
0
|
0
|
|
my $g = shift;
|
30
|
0
|
|
|
|
|
|
my $p = Graph::NewmanGirvan->new;
|
31
|
0
|
|
|
|
|
|
my %default_weight;
|
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
for ($g->edges) {
|
34
|
0
|
|
|
|
|
|
my ($src, $dst) = @$_;
|
35
|
0
|
|
0
|
|
|
|
my $weight = $g->get_edge_weight($src, $dst) // 1.0;
|
36
|
0
|
|
|
|
|
|
$p->add_edge($src, $dst, $weight);
|
37
|
0
|
|
|
|
|
|
$default_weight{$src} += $weight;
|
38
|
0
|
|
|
|
|
|
$default_weight{$dst} += $weight;
|
39
|
|
|
|
|
|
|
}
|
40
|
0
|
|
|
|
|
|
foreach my $vertex ($g->vertices) {
|
41
|
0
|
|
0
|
|
|
|
my $weight = $g->get_vertex_weight($vertex) // $default_weight{$vertex};
|
42
|
0
|
|
|
|
|
|
$p->set_vertex_weight($vertex, $weight);
|
43
|
|
|
|
|
|
|
}
|
44
|
0
|
|
|
|
|
|
return $p->compute;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub newman_girvan_r {
|
48
|
0
|
|
|
0
|
0
|
|
my ($g) = @_;
|
49
|
0
|
|
|
|
|
|
my %clustering = newman_girvan($g);
|
50
|
0
|
|
|
|
|
|
my %reverse;
|
51
|
0
|
|
|
|
|
|
push @{ $reverse{ $clustering{$_} } }, $_ for keys %clustering;
|
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
%reverse;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1;
|
57
|
|
|
|
|
|
|
__END__
|