Maker/Degree.pm

filter: Statementstmt 98.4% 63 / 64 Branchbran 72.7% 16 / 22 Conditioncond 59.3% 19 / 32 MC/DCmcdc 29.4% 5 / 17 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 1 totaltotal 76.8% 113 / 147 CC 28 SCAR 31.2
CC
28
Cov
83%
init
32.5
__ANON__
3.0
__ANON__
1.1
CRAP 22.7
« Maker/SmallWorldK.pm ↑ Summary Maker/Bipartite.pm »
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
l!l
16
MC/DC100%1/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table100%2/2
A
A= delete $params{'N'}
Aresult
11
00
18 7 ▶ my $seq = delete($params{seq}) || 0;
Condition50%1/2
delete $params{'seq'} || 0
l!l
70
MC/DC0%0/1
delete $params{'seq'} || 0
delete $params{'seq'}
Truth table50%1/2
A
A= delete $params{'seq'}
Aresult
11
00
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
BranchTrueFalseTotal
if $gm and ref $gm ne "CODE" 0 7 7
Condition33%1/3
$gm and ref $gm ne "CODE"
!ll&&!rl&&r
700
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"
ABresult
0X0
100
111
22 7 ▶ $gm ||= sub { new Graph(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub { "Graph"->new(@_); }
l!l&&r!l&&!r
070
MC/DC0%0/2
$gm ||= sub { "Graph"->new(@_); }
$gm sub { "Graph"->new(@_); }
Truth table33%1/3
A ||= B
A= $gmB= sub { "Graph"->new(@_); }
ABresult
1X1
011
000
23
24 7 ▶ croak "seq must be an array reference and be a valid degree sequence\n" unless
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq and ref $seq eq "ARRAY" and is_valid_degree_seq(@$seq) 1 6 7
Condition50%3/6
defined $seq and ref $seq eq "ARRAY" and is_valid_degree_seq(@$seq)
!ll&&!rl&&r
016
defined $seq and ref $seq eq "ARRAY"
!ll&&!rl&&r
007
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)
ABCresult
0XX0
10X0
1100
1111
25 defined $seq &&
26 ref($seq) eq 'ARRAY'
27 && is_valid_degree_seq(@$seq);
28
29 6 ▶ $n = @$seq if !$n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 6 0 6
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
l!l
560
MC/DC0%0/1
$$seq[$_ - 1] || 0
$$seq[$_ - 1]
Truth table50%1/2
A
A= $$seq[$_ - 1]
Aresult
11
00
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
l!l
240246
$c{$b} || 0
l!l
230256
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}
Aresult
11
00
Truth table100%2/2
A
A= $c{$b}
Aresult
11
00
39 0 ▶ sub { random_permutation(@_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
$strict ? : 6 0 6
40
41 6 foreach my $v(1..$n)
42 {
43 56 ▶ $c{$v} ||= 0;
Condition100%2/2
$c{$v} ||= 0
l!l
4610
MC/DC100%1/1
$c{$v} ||= 0
$c{$v}
Truth table100%2/2
A
A= $c{$v}
Aresult
11
00
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
BranchTrueFalseTotal
unless ($$seq[$v - 1] || 0) > 0 0 56 56
Condition50%1/2
$$seq[$v - 1] || 0
l!l
560
MC/DC0%0/1
$$seq[$v - 1] || 0
$$seq[$v - 1]
Truth table50%1/2
A
A= $$seq[$v - 1]
Aresult
11
00
48 #print "\tH\n";
49 56 ▶ next if $c{$v} >= $seq->[$v-1];
Branch: 1 branch
BranchTrueFalseTotal
if $c{$v} >= $$seq[$v - 1] 18 38 56
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
BranchTrueFalseTotal
unless $i - $s < @a 0 70 70
55 70 ▶ $s-- if $a[$i-$s] == $v; # be sure not to connect a node to itself
Branch: 1 branch
BranchTrueFalseTotal
if $a[$i - $s] == $v 12 58 70
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
BranchTrueFalseTotal
unless $g->is_undirected 35 35 70
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
BranchTrueFalseTotal
if ($c{$a[$i - $s]} >= $$seq[$a[$i - $s] - 1]) 18 52 70
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
BranchTrueFalseTotal
if $strict and scalar grep({($$seq[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n) 0 6 6
Condition50%3/6
$strict and scalar grep({($$seq[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n)
!ll
06
$$seq[$_ - 1] || 0
l!l
560
$c{$_} || 0
l!l
560
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
Aresult
00
11
Truth table50%1/2
A
A= $$seq[$_ - 1]
Aresult
11
00
Truth table50%1/2
A
A= $c{$_}
Aresult
11
00
75
76 6 return $g;
77 }
78
79 2 Graph::Maker->add_factory_type( 'degree' => __PACKAGE__ );
80
81 2 1;
82
83 __DATA__
« Maker/SmallWorldK.pm ↑ Summary Maker/Bipartite.pm »