| 1 | package Graph::Maker::Random; | ||||||||||||||||||||||||||||
| 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 Graph::Maker::Complete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Graph::Maker::Utils qw/is_valid_degree_seq/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Math::Random qw/random_uniform_integer random_uniform/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub init | ||||||||||||||||||||||||||||
| 15 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=10 SCAR=25.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 4 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | 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'}
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | my $m = delete($params{M}) || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{'M'} || 0
MC/DC100%1/1
delete $params{'M'} || 0
delete $params{'M'}
Truth table100%2/2
A
A= delete $params{'M'}
| |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | my $p = delete($params{PR})|| 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{'PR'} || 0
MC/DC100%1/1
delete $params{'PR'} || 0
delete $params{'PR'}
Truth table100%2/2
A
A= delete $params{'PR'}
| |||||||||||||||||||||||||||||
| 21 | 4 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||
| 22 | 4 | ▶ | 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"
| |||||||||||||||||||||||||||||
| 23 | 4 | ▶ | $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(@_);
}
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | if($p == 1 || $m >= $n*($n-1)/2) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p == 1 or $m >= $n * ($n - 1) / 2
MC/DC0%0/2
$p == 1 or $m >= $n * ($n - 1) / 2
$p == 1
$m >= $n * ($n - 1) / 2
Truth table33%1/3
A or B
A= $p == 1B= $m >= $n * ($n - 1) / 2
| |||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 0 | return new Graph::Maker('complete', N => $n, graph_maker => $gm, %params); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | my $g = $gm->(%params); | |||||||||||||||||||||||||||
| 31 | 4 | $g->add_vertices(1..$n); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | return erdos($g, $n, $p) if $p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | return random($g, $n, $m); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub erdos | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
erdos: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 2 | my ($g, $n, $p, $m) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | for my $u(1..$n) | |||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 200 | for my $v(1..$n) | |||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 20000 | ▶ | next if $u == $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 19800 | ▶ | if(random_uniform() < $p) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 2144 | $g->add_edge($u, $v); | |||||||||||||||||||||||||||
| 49 | 2144 | ▶ | $g->add_edge($v, $u) if $g->is_directed(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 2 | return $g; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub random | ||||||||||||||||||||||||||||
| 57 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
random: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 2 | my ($g, $n, $m) = @_; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | for (1..$m) | |||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 152 | my @e = random_uniform_integer(2, 1, $n); | |||||||||||||||||||||||||||
| 63 | 152 | ▶ | redo if $e[0] == $e[1] || $g->has_edge(@e); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e[0] == $e[1] or $g->has_edge(@e)
MC/DC50%1/2
$e[0] == $e[1] or $g->has_edge(@e)
$e[0] == $e[1]
$g->has_edge(@e)
Truth table66%2/3
A or B
A= $e[0] == $e[1]B= $g->has_edge(@e)
| |||||||||||||||||||||||||||||
| 64 | 150 | $g->add_edge(@e); | |||||||||||||||||||||||||||
| 65 | 150 | ▶ | $g->add_edge(reverse @e) unless $g->is_undirected(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 2 | return $g; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | Graph::Maker->add_factory_type( 'random' => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __DATA__ | ||||||||||||||||||||||||||||