| 1 | package Graph::Maker::Regular; | ||||||||||||||||||||||||||||
| 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_integer/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub init | ||||||||||||||||||||||||||||
| 13 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=22 SCAR=31.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 4 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 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'}
| |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | 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 | 4 | ▶ | $k = $n if $k > $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | croak "N*K (" . ($n*$k) . ") must be even\n" if ($n*$k) & 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 4 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||
| 21 | 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"
| |||||||||||||||||||||||||||||
| 22 | 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(@_);
}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | my $g = $gm->(%params); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | my @a = (1..$n); | |||||||||||||||||||||||||||
| 27 | 4 | my %c; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | ▶ | while(@a > 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||
| 31 | 51 | my @e = random_uniform_integer(2, 0, @a-1); | |||||||||||||||||||||||||||
| 32 | 51 | ▶ | if($e[0] != $e[1] && !$g->has_edge(@a[@e])) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$e[0] != $e[1] and not $g->has_edge(@a[@e])
MC/DC100%2/2
$e[0] != $e[1] and not $g->has_edge(@a[@e])
$e[0] != $e[1]
not $g->has_edge(@a[@e])
Truth table100%3/3
A and not(B)
A= $e[0] != $e[1]B= not $g->has_edge(@a[@e])
| |||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 26 | $g->add_edge(@a[@e]); | |||||||||||||||||||||||||||
| 35 | 26 | ▶ | $g->add_edge(reverse @a[@e]) unless $g->is_undirected(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 26 | $c{$a[$e[0]]}++; | |||||||||||||||||||||||||||
| 37 | 26 | $c{$a[$e[1]]}++; | |||||||||||||||||||||||||||
| 38 | #print "\tAdded @a[@e]\t[@a]\n"; | ||||||||||||||||||||||||||||
| 39 | 26 | ▶ | if($c{$a[$e[0]]} >= $k) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | #print "\tRemoving $c{$a[$e[0]]} $a[$e[0]]\n"; | ||||||||||||||||||||||||||||
| 42 | 10 | splice(@a, $e[0], 1); | |||||||||||||||||||||||||||
| 43 | 10 | ▶ | $e[1]-- if $e[1] > $e[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 26 | ▶ | splice(@a, $e[1], 1) if $c{$a[$e[1]]} >= $k; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | #print "\t\t\t[@a]\n"; | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | else | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | #print "\twarnings...$a[$e[0]] $a[$e[1]]\n"; | ||||||||||||||||||||||||||||
| 51 | 25 | my $b = 0; | |||||||||||||||||||||||||||
| 52 | 25 | foreach my $u(@a) | |||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 50 | ▶ | last if $b; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 26 | foreach my $v(@a) | |||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 52 | ▶ | do {$b = 1; last} if $u != $v && !$g->has_edge($u, $v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$u != $v and not $g->has_edge($u, $v)
MC/DC100%2/2
$u != $v and not $g->has_edge($u, $v)
$u != $v
not $g->has_edge($u, $v)
Truth table100%3/3
A and not(B)
A= $u != $vB= not $g->has_edge($u, $v)
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 25 | ▶ | next if $b; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 1 | croak "Could not form the requested graph...\n"; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | croak "Could not form the requested graph...\n" if @a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 3 | return $g; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | Graph::Maker->add_factory_type( 'regular' => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __DATA__ | ||||||||||||||||||||||||||||