| 1 | package Graph::TransitiveClosure::Matrix; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Graph::AdjacencyMatrix; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Graph::Matrix; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | sub _A() { 0 } # adjacency | ||||||||||||||||||||||||||||||||||||||||||
| 12 | sub _D() { 1 } # distance | ||||||||||||||||||||||||||||||||||||||||||
| 13 | sub _S() { 2 } # successors | ||||||||||||||||||||||||||||||||||||||||||
| 14 | sub _V() { 3 } # vertices | ||||||||||||||||||||||||||||||||||||||||||
| 15 | sub _G() { 4 } # the original graph (OG) | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 70 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=37 SCAR=36.1
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 70 | my ($g, $class, $am_opt, $want_transitive, $want_reflexive, $want_path, $want_path_vertices, $want_path_count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 70 | my $m = Graph::AdjacencyMatrix->new($g, %$am_opt); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 70 | my @V = $g->vertices; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 70 | my %v2i; @v2i{ @V } = 0..$#V; # paths are in array -> stable ordering | |||||||||||||||||||||||||||||||||||||||||
| 22 | 70 | my $am = $m->adjacency_matrix; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 70 | $am->[1] = \%v2i; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 70 | my ($dm, @di); # The distance matrix. | |||||||||||||||||||||||||||||||||||||||||
| 25 | 70 | my ($sm, @si); # The successor matrix. | |||||||||||||||||||||||||||||||||||||||||
| 26 | # directly use (not via API) arrays of bit-vectors etc for speed. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # the API is so low-level it adds no clarity anyway | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 70 | my @ai = @{ $am->[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 70 | my $multi = $g->multiedged; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 70 | ▶ | unless ($want_transitive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 60 | ▶ | $dm = $m->distance_matrix || Graph::Matrix->new($g); # if no distance_matrix in AM, we make our own | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$m->distance_matrix || 'Graph::Matrix'->new($g)
MC/DC0%0/2
$m->distance_matrix || 'Graph::Matrix'->new($g)
$m->distance_matrix
'Graph::Matrix'->new($g)
Truth table66%2/3
A || B
A= $m->distance_matrixB= 'Graph::Matrix'->new($g)
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 60 | ▶ | if ($want_path_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | # force defined | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | @di = map [ (0) x @V ], 0..$#V; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 59 | @di = @{ $dm->[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 60 | $sm = Graph::Matrix->new($g); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 60 | $dm->[1] = $sm->[1] = \%v2i; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 60 | @si = @{ $sm->[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 60 | ▶ | for (my $iu = $#V; $iu >= 0; $iu--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 437 | ▶ | vec($ai[$iu], $iu, 1) = 1 if $want_reflexive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 437 | ▶ | for (my $iv = $#V; $iv >= 0; $iv--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 17011 | ▶ | next unless vec($ai[$iu], $iv, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1164 | ▶ | if ($want_path_count or !defined $di[$iu][$iv]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$want_path_count or not defined $di[$iu][$iv]
MC/DC100%2/2
$want_path_count or not defined $di[$iu][$iv]
$want_path_count
not defined $di[$iu][$iv]
Truth table100%3/3
A or not(B)
A= $want_path_countB= not defined $di[$iu][$iv]
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 231 | ▶ | $di[$iu][$iv] = $iu == $iv ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | ▶ | } elsif ($multi and ref($di[$iu][$iv]) eq 'HASH') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$multi and ref $di[$iu][$iv] eq "HASH"
MC/DC100%2/2
$multi and ref $di[$iu][$iv] eq "HASH"
$multi
ref $di[$iu][$iv] eq "HASH"
Truth table100%3/3
A and B
A= $multiB= ref $di[$iu][$iv] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | $di[$iu][$iv] = min values %{ $di[$iu][$iv] }; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 1164 | ▶ | $si[$iu]->[$iv] = $V[$iv] unless $iu == $iv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # naming here is u = start, v = midpoint, w = endpoint | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 70 | ▶ | for (my $iv = $#V; $iv >= 0; $iv--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 466 | my $div = $di[$iv]; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 466 | my $aiv = $ai[$iv]; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 466 | ▶ | for (my $iu = $#V; $iu >= 0; $iu--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 17115 | my $aiu = $ai[$iu]; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 17115 | ▶ | next if !vec($aiu, $iv, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2010 | ▶ | if ($want_transitive) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 55 | ▶ | for (my $iw = $#V; $iw >= 0; $iw--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 195 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$iw != $iv and vec $aiv, $iw, 1 and not vec($aiu, $iw, 1)
$iw != $iv and vec $aiv, $iw, 1
MC/DC100%3/3
$iw != $iv and vec $aiv, $iw, 1 and not vec($aiu, $iw, 1)
$iw != $iv
vec $aiv, $iw, 1
not vec($aiu, $iw, 1)
Truth table100%4/4
A and B and not(C)
A= $iw != $ivB= vec $aiv, $iw, 1C= not vec($aiu, $iw, 1)
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | if $iw != $iv && | ||||||||||||||||||||||||||||||||||||||||||
| 65 | vec($aiv, $iw, 1) && | ||||||||||||||||||||||||||||||||||||||||||
| 66 | !vec($aiu, $iw, 1); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 51 | next; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1955 | my $aiuo = $aiu; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1955 | $aiu |= $aiv; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1955 | ▶ | if ($aiu ne $aiuo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 978 | $ai[$iu] = $aiu; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 978 | ▶ | $aiv = $aiu if $iv == $iu; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 1955 | ▶ | next if !$want_path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1935 | my $diu = $di[$iu]; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1935 | my $d1a = $diu->[$iv]; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1935 | ▶ | for (my $iw = $#V; $iw >= 0; $iw--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 94495 | ▶ | next unless vec($aiv, $iw, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 28227 | ▶ | if ($want_path_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 13 | ▶ | $diu->[$iw]++ if $iu != $iv and $iv != $iw and $iw != $iu; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$iu != $iv and $iv != $iw and $iw != $iu
$iu != $iv and $iv != $iw
MC/DC66%2/3
$iu != $iv and $iv != $iw and $iw != $iu
$iu != $iv
$iv != $iw
$iw != $iu
Truth table75%3/4
A and B and C
A= $iu != $ivB= $iv != $iwC= $iw != $iu
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 13 | next; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 28214 | my $d0 = $diu->[$iw]; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 28214 | my $d1b = $div->[$iw]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 28214 | my $d1 = $d1a + $d1b; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 28214 | ▶ | if (!defined $d0 || ($d1 < $d0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $d0 or $d1 < $d0
MC/DC100%2/2
not defined $d0 or $d1 < $d0
not defined $d0
$d1 < $d0
Truth table100%3/3
not(A) or B
A= not defined $d0B= $d1 < $d0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | # print "d1 = $d1a ($V[$iu], $V[$iv]) + $d1b ($V[$iv], $V[$iw]) = $d1 ($V[$iu], $V[$iw]) (".(defined$d0?$d0:"-").") (propagate=".($aiu ne $aiuo?1:0).")\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 7336 | $diu->[$iw] = $d1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 7336 | ▶ | $si[$iu]->[$iw] = $si[$iu]->[$iv] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | if $want_path_vertices; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 66 | ▶ | return 1 if $want_transitive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 60 | my %V; @V{ @V } = @V; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 60 | $am->[0] = \@ai; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 60 | ▶ | $dm->[0] = \@di if defined $dm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 60 | ▶ | $sm->[0] = \@si if defined $sm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 60 | weaken(my $og = $g); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 60 | bless [ $am, $dm, $sm, \%V, $og ], $class; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 70 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 70 | my ($class, $g, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 70 | my %am_opt = (distance_matrix => 1); | |||||||||||||||||||||||||||||||||||||||||
| 109 | $am_opt{attribute_name} = delete $opt{attribute_name} | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 70 | ▶ | if exists $opt{attribute_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | $am_opt{distance_matrix} = delete $opt{distance_matrix} | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 70 | ▶ | if $opt{distance_matrix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | $opt{path_length} = $opt{path_vertices} = delete $opt{path} | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 70 | ▶ | if exists $opt{path}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 70 | my $want_path_length = delete $opt{path_length}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 70 | my $want_path_count = delete $opt{path_count}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 70 | my $want_path_vertices = delete $opt{path_vertices}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 70 | my $want_reflexive = delete $opt{reflexive}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | $am_opt{is_transitive} = my $want_transitive = delete $opt{is_transitive} | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 70 | ▶ | if exists $opt{is_transitive}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 70 | Graph::_opt_unknown(\%opt); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 70 | ▶ | $want_reflexive = 1 unless defined $want_reflexive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 70 | ▶ | my $want_path = $want_path_length || $want_path_vertices || $want_path_count; | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$want_path_length || $want_path_vertices || $want_path_count
$want_path_length or $want_path_vertices
MC/DC66%2/3
$want_path_length || $want_path_vertices || $want_path_count
$want_path_length
$want_path_vertices
$want_path_count
Truth table75%3/4
A or B || C
A= $want_path_lengthB= $want_path_verticesC= $want_path_count
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | # $g->expect_dag if $want_path; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 70 | ▶ | $am_opt{distance_matrix} = 0 if $want_path_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 70 | _new($g, $class, | |||||||||||||||||||||||||||||||||||||||||
| 127 | \%am_opt, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | $want_transitive, $want_reflexive, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | $want_path, $want_path_vertices, $want_path_count); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 17736 | ▶ | sub has_vertices { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_vertices: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 17736 | my $tc = shift; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 17736 | for my $v (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 135 | 35466 | ▶ | return 0 unless exists $tc->[ _V ]->{ $v }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 17727 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 14352 | ▶ | sub is_reachable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_reachable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 14352 | my ($tc, $u, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 14352 | ▶ | return undef unless $tc->has_vertices($u, $v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 14346 | ▶ | return 1 if $u eq $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 13480 | $tc->[ _A ]->get($u, $v); | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 16 | ▶ | sub is_transitive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_transitive: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 16 | ▶ | return __PACKAGE__->new($_[0], is_transitive => 1) if @_ == 1; # Any graph | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | # A TC graph | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | my ($tc, $u, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | ▶ | return undef unless $tc->has_vertices($u, $v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | $tc->[ _A ]->get($u, $v); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 603 | ▶ | sub vertices { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vertices: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 603 | my $tc = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 603 | values %{ $tc->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 3007 | ▶ | sub path_length { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_length: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 3007 | my ($tc, $u, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 3007 | ▶ | return undef unless $tc->has_vertices($u, $v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3004 | ▶ | return 0 if $u eq $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 2748 | $tc->[ _D ]->get($u, $v); | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 380 | ▶ | sub path_successor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_successor: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 380 | my ($tc, $u, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 380 | ▶ | return undef if $u eq $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 371 | ▶ | return undef unless $tc->has_vertices($u, $v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 371 | $tc->[ _S ]->get($u, $v); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 267 | ▶ | sub path_vertices { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_vertices: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 267 | my ($tc, $u, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 267 | ▶ | return unless $tc->is_reachable($u, $v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 252 | ▶ | return wantarray ? () : 0 if $u eq $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 207 | my @v = ( $u ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 207 | ▶ | while ($u ne $v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 353 | ▶ | last unless defined($u = $tc->path_successor($u, $v)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 353 | push @v, $u; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 207 | ▶ | $tc->[ _S ]->set($u, $v, [ @v ]) if @v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 207 | return @v; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 29 | ▶ | sub all_paths { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_paths: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 29 | my ($tc, $u, $v, $seen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 29 | ▶ | return if $u eq $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 29 | ▶ | $seen ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$seen ||= {}
MC/DC100%1/1
$seen ||= {}
$seen
Truth table100%2/2
A
A= $seen
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 29 | ▶ | return if exists $seen->{$u}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 28 | $seen = { %$seen, $u => undef }; # accumulate, but don't mutate | |||||||||||||||||||||||||||||||||||||||||
| 193 | 28 | my @found; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 28 | ▶ | push @found, [$u, $v] if $tc->[ _G ]->has_edge($u, $v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 28 | ▶ | push @found, | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne $v && $_ ne $u
MC/DC100%2/2
$_ ne $v && $_ ne $u
$_ ne $v
$_ ne $u
Truth table100%3/3
A && B
A= $_ ne $vB= $_ ne $u
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | map [$u, @$_], | ||||||||||||||||||||||||||||||||||||||||||
| 197 | map $tc->all_paths($_, $v, $seen), | ||||||||||||||||||||||||||||||||||||||||||
| 198 | grep $tc->is_reachable($_, $v), | ||||||||||||||||||||||||||||||||||||||||||
| 199 | grep $_ ne $v && $_ ne $u, $tc->[ _G ]->successors($u); | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 28 | @found; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 204 | __END__ | ||||||||||||||||||||||||||||||||||||||||||