| 1 | package Graph::Maker::SmallWorldWS; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw/Graph::Maker/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Graph; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Math::Random qw/random_uniform random_uniform_integer/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub init | ||||||||||||||||||||||||||||
| 13 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=19 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 3 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | my $n = delete($params{N}) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'N'} || 0
MC/DC0%0/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table50%1/2
A
A= delete $params{'N'}
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | my $k = delete($params{K}) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'K'} || 0
MC/DC0%0/1
delete $params{'K'} || 0
delete $params{'K'}
Truth table50%1/2
A
A= delete $params{'K'}
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | my $p = delete($params{PR}) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'PR'} || 0
MC/DC0%0/1
delete $params{'PR'} || 0
delete $params{'PR'}
Truth table50%1/2
A
A= delete $params{'PR'}
| |||||||||||||||||||||||||||||
| 19 | 3 | my $a = delete($params{keep_edges}); | |||||||||||||||||||||||||||
| 20 | 3 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||
| 21 | 3 | ▶ | croak "graph_maker must be a reference to a function that creates a Graph.\n" if $gm && ref($gm) ne 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$gm and ref $gm ne "CODE"
MC/DC0%0/2
$gm and ref $gm ne "CODE"
$gm
ref $gm ne "CODE"
Truth table33%1/3
A and B
A= $gmB= ref $gm ne "CODE"
| |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | $gm ||= sub { new Graph(@_); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub {
"Graph"->new(@_);
}
MC/DC0%0/2
$gm ||= sub {
"Graph"->new(@_);
}
$gm
sub {
"Graph"->new(@_);
}
Truth table33%1/3
A ||= B
A= $gmB= sub {
"Graph"->new(@_);
}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | $k = $n if $k > $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | my $g = $gm->(%params); | |||||||||||||||||||||||||||
| 27 | 3 | my @v = (1..$n); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # Connect initial ring | ||||||||||||||||||||||||||||
| 30 | 3 | foreach my $v(@v) | |||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 300 | for my $w(1..int($k/2 + .5)) | |||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 400 | my $j = $v + $w; | |||||||||||||||||||||||||||
| 35 | 400 | ▶ | $j = ($j % $n) if $j > $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 400 | $g->add_edge($v, $j); | |||||||||||||||||||||||||||
| 37 | 400 | ▶ | $g->add_edge($j, $v) unless $g->is_undirected(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Rewire | ||||||||||||||||||||||||||||
| 42 | 3 | foreach my $e($g->edges()) | |||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 500 | ▶ | if(random_uniform() < $p) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 160 | my $w = random_uniform_integer(1, 1, $n); | |||||||||||||||||||||||||||
| 47 | 160 | ▶ | $w = random_uniform_integer(1, 1, $n) until $w != $e->[0] && !$g->has_edge($e->[0], $w); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$w != $e->[0] and not $g->has_edge($e->[0], $w)
MC/DC50%1/2
$w != $e->[0] and not $g->has_edge($e->[0], $w)
$w != $e->[0]
not $g->has_edge($e->[0], $w)
Truth table66%2/3
A and not(B)
A= $w != $e->[0]B= not $g->has_edge($e->[0], $w)
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 160 | ▶ | $g->delete_edge(@$e) unless $a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 160 | ▶ | $g->delete_edge(reverse @$e) unless $a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 160 | $g->add_edge($e->[0], $w); | |||||||||||||||||||||||||||
| 52 | 160 | ▶ | $g->add_edge($w, $e->[0]) unless $g->is_undirected(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | return $g; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | Graph::Maker->add_factory_type( 'small_world_ws' => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __DATA__ | ||||||||||||||||||||||||||||