| 1 | package Graph::Maker::Degree; | ||||||||||||||||||||||||||||||||||||||||||
| 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::Utils qw/is_valid_degree_seq/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Math::Random qw/random_permuted_index random_permutation/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=26 SCAR=34.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | my $n = delete($params{N}) || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{'N'} || 0
MC/DC100%1/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table100%2/2
A
A= delete $params{'N'}
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | my $seq = delete($params{seq}) || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'seq'} || 0
MC/DC0%0/1
delete $params{'seq'} || 0
delete $params{'seq'}
Truth table50%1/2
A
A= delete $params{'seq'}
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | my $strict = delete($params{strict}); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | 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 | 7 | ▶ | $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 | 7 | ▶ | croak "seq must be an array reference and be a valid degree sequence\n" unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $seq and ref $seq eq "ARRAY" and is_valid_degree_seq(@$seq)
defined $seq and ref $seq eq "ARRAY"
MC/DC33%1/3
defined $seq and ref $seq eq "ARRAY" and is_valid_degree_seq(@$seq)
defined $seq
ref $seq eq "ARRAY"
is_valid_degree_seq(@$seq)
Truth table50%2/4
A and B and C
A= defined $seqB= ref $seq eq "ARRAY"C= is_valid_degree_seq(@$seq)
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | defined $seq && | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ref($seq) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 27 | && is_valid_degree_seq(@$seq); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | $n = @$seq if !$n; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my $g = $gm->(%params); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | $g->add_vertices(1..$n); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | my @a = grep {($seq->[$_-1]||0) > 0} (1..$n); # create a list of available nodes | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$seq[$_ - 1] || 0
MC/DC0%0/1
$$seq[$_ - 1] || 0
$$seq[$_ - 1]
Truth table50%1/2
A
A= $$seq[$_ - 1]
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | # if strict use fill the largest degree nodes first | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | my %c; | |||||||||||||||||||||||||||||||||||||||||
| 37 | my $sort = $strict ? | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 56 | ▶ | sub { reverse sort {$seq->[$a-1]-($c{$a}||0) <=> $seq->[$b-1]-($c{$b}||0)} @_ } : | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Condition100%4/4
$c{$a} || 0
$c{$b} || 0
MC/DC100%1/1
$c{$a} || 0
$c{$a}
MC/DC100%1/1
$c{$b} || 0
$c{$b}
Truth table100%2/2
A
A= $c{$a}
Truth table100%2/2
A
A= $c{$b}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub { random_permutation(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | foreach my $v(1..$n) | |||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 56 | ▶ | $c{$v} ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c{$v} ||= 0
MC/DC100%1/1
$c{$v} ||= 0
$c{$v}
Truth table100%2/2
A
A= $c{$v}
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 56 | @a = $sort->(@a); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 56 | my $s = 0; | |||||||||||||||||||||||||||||||||||||||||
| 46 | #print "\t$v: $c{$v} >= $seq->[$v-1]\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 56 | ▶ | next unless ($seq->[$v-1]||0) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$seq[$v - 1] || 0
MC/DC0%0/1
$$seq[$v - 1] || 0
$$seq[$v - 1]
Truth table50%1/2
A
A= $$seq[$v - 1]
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | #print "\tH\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 56 | ▶ | next if $c{$v} >= $seq->[$v-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | #print "\tB [@a]\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # Add the edges specified | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 38 | for my $i(0..$seq->[$v-1]-1-$c{$v}) | |||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 70 | ▶ | last unless $i-$s < @a; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 70 | ▶ | $s-- if $a[$i-$s] == $v; # be sure not to connect a node to itself | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | #print "\t$v -> $a[$i-$s] |@a| $i $s\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 70 | $g->add_edge($v, $a[$i-$s]); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 70 | ▶ | $g->add_edge($a[$i-$s], $v) unless $g->is_undirected(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 70 | $c{$a[$i-$s]}++; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 70 | $c{$v}++; | |||||||||||||||||||||||||||||||||||||||||
| 61 | #print "\tINC: $a[$i-$s] -> $c{$a[$i-$s]} >= $seq->[$a[$i-$s]-1] ($a[$i-$s]) (@$seq)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 70 | ▶ | if($c{$a[$i-$s]} >= $seq->[$a[$i-$s]-1]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 18 | splice(@a, $i-$s, 1); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 18 | $s++; | |||||||||||||||||||||||||||||||||||||||||
| 66 | #print "\tS |@a| $i $s\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 38 | @a = grep {$_ != $v} @a; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | croak "Could not build a graph with the requested sequences (@$seq)\n" if $strict && | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | scalar(grep {($seq->[$_-1]||0) != ($c{$_}||0)} (1..$n)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$strict and scalar grep({($$seq[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n)
$$seq[$_ - 1] || 0
$c{$_} || 0
MC/DC0%0/1
$strict and scalar grep({($$seq[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n)
$strict
MC/DC0%0/1
$$seq[$_ - 1] || 0
$$seq[$_ - 1]
MC/DC0%0/1
$c{$_} || 0
$c{$_}
Truth table50%1/2
A
A= $strict
Truth table50%1/2
A
A= $$seq[$_ - 1]
Truth table50%1/2
A
A= $c{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | return $g; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | Graph::Maker->add_factory_type( 'degree' => __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||