| 1 | package Graph::Maker::Bipartite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my $n1 = delete($params{N1}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | my $n2 = delete($params{N2}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | #my $deg = delete($params{K}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | my $degSeqA = delete($params{seq1}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | my $degSeqB = delete($params{seq2}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | my $strict = delete($params{strict}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | ▶ | $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(@_);
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | my $g = $gm->(%params); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #return random_deg($g, $n1, $n2, $deg) if $deg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | return random_seq($g, $n1, $n2, $degSeqA, $degSeqB, $strict); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #sub random_deg | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | #{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # my ($g, $n1, $n2, $deg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # croak "N1 must be defined and greater than 0\n" unless defined $n1 && $n1 > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # croak "N2 must be defined and greater than 0\n" unless defined $n2 && $n2 > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | sub random_seq | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
random_seq: called CC=25 SCAR=33.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | my ($g, $n1, $n2, $a1, $a2, $strict) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | $n1 ||= @$a1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$n1 ||= @$a1
MC/DC0%0/2
$n1 ||= @$a1
$n1
@$a1
Truth table66%2/3
A ||= B
A= $n1B= @$a1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | $n2 ||= @$a2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$n2 ||= @$a2
MC/DC0%0/2
$n2 ||= @$a2
$n2
@$a2
Truth table66%2/3
A ||= B
A= $n2B= @$a2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | $g->add_vertices(1..$n1+$n2); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | croak "The maximum degree in [@$a] must be $n2\n" if grep {$_ > $n2} @$a; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | croak "The maximum degree in [@$a] must be $n1\n" if grep {$_ > $n1} @$b; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | my ($sa, $sb) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | $sa += $_ foreach (@$a1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | $sb += $_ foreach (@$a2); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | croak "sum([@$a1]) must equal sum([@$b])\n" unless $sa == $sb; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | my @a = grep {($a1->[$_-1]||0) > 0} (1..$n1); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$a1[$_ - 1] || 0
MC/DC100%1/1
$$a1[$_ - 1] || 0
$$a1[$_ - 1]
Truth table100%2/2
A
A= $$a1[$_ - 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | ▶ | my @b = grep {($a2->[$_-$n1-1]||0) > 0} ($n1+1..$n1+$n2); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$a2[$_ - $n1 - 1] || 0
MC/DC100%1/1
$$a2[$_ - $n1 - 1] || 0
$$a2[$_ - $n1 - 1]
Truth table100%2/2
A
A= $$a2[$_ - $n1 - 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | my %c; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # if strict use fill the largest degree nodes first | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | my $sort = $strict ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 32 | ▶ | sub { reverse sort {$a2->[$b-$n1-1]-($c{$a}||0) <=> $a2->[$b-$n1-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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub { random_permutation(@_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | foreach my $v(@a) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 32 | @b = $sort->(@b); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 32 | my $s = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 32 | ▶ | next unless ($a1->[$v-1]||0) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$a1[$v - 1] || 0
MC/DC0%0/1
$$a1[$v - 1] || 0
$$a1[$v - 1]
Truth table50%1/2
A
A= $$a1[$v - 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 32 | for my $i(0..$a1->[$v-1]-1) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 54 | ▶ | last unless $i-$s < @b; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | #print "\t$v -> $b[$i-$s] |@b| $i $s\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 52 | $g->add_edge($v, $b[$i-$s]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 52 | ▶ | $g->add_edge($b[$i-$s], $v) unless $g->is_undirected(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 52 | $c{$b[$i-$s]}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 52 | $c{$v}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 52 | ▶ | if($c{$b[$i-$s]} >= $a2->[$b[$i-$s]-$n1-1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 28 | splice(@b, $i-$s, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 28 | $s++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #print "\tS |@b| $i $s\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # print "\t$_: " . ($a1->[$_-1]||0) . " " . ($c{$_}||0) . "\n" foreach (sort {$a<=>$b} (1..$n1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # print "\t$_: " . ($a2->[$_-$n2-1]||0) . " " . ($c{$_}||0) . "\n" foreach (sort {$a<=>$b} ($n1+1..$n1+$n2)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # print "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # print "\t\t" . join(', ', grep {($a1->[$_-1]||0) == ($c{$_}||0)} (1..$n1)) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # print "\t\t" . join(', ', grep {($a2->[$_-$n1-1]||0) != ($c{$_}||0)} ($n1+1..$n1+$n2)) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | croak "Could not build a graph with the requested sequences (@$a1), (@$a2)\n" if $strict && | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 40 | ▶ | (scalar(grep {($a1->[$_-1]||0) != ($c{$_}||0)} (1..$n1)) || | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$$a1[$_ - 1] || 0
$c{$_} || 0
MC/DC100%1/1
$$a1[$_ - 1] || 0
$$a1[$_ - 1]
MC/DC100%1/1
$c{$_} || 0
$c{$_}
Truth table100%2/2
A
A= $$a1[$_ - 1]
Truth table100%2/2
A
A= $c{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | ▶ | scalar(grep {($a2->[$_-$n1-1]||0) != ($c{$_}||0)} ($n1+1..$n1+$n2))); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$strict and scalar grep({($$a1[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n1) || scalar grep({($$a2[$_ - $n1 - 1] || 0) != ($c{$_} || 0);} $n1 + 1 .. $n1 + $n2)
scalar grep({($$a1[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n1) or scalar grep({($$a2[$_ - $n1 - 1] || 0) != ($c{$_} || 0);} $n1 + 1 .. $n1 + $n2)
$$a2[$_ - $n1 - 1] || 0
$c{$_} || 0
MC/DC50%1/2
$strict and scalar grep({($$a1[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n1) || scalar grep({($$a2[$_ - $n1 - 1] || 0) != ($c{$_} || 0);} $n1 + 1 .. $n1 + $n2)
$strict
scalar grep({($$a1[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n1)
MC/DC0%0/1
$$a2[$_ - $n1 - 1] || 0
$$a2[$_ - $n1 - 1]
MC/DC0%0/1
$c{$_} || 0
$c{$_}
Truth table66%2/3
A and B
A= $strictB= scalar grep({($$a1[$_ - 1] || 0) != ($c{$_} || 0);} 1 .. $n1)
Truth table50%1/2
A
A= $$a2[$_ - $n1 - 1]
Truth table50%1/2
A
A= $c{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | return $g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | Graph::Maker->add_factory_type( 'bipartite' => __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||