| 1 | package Graph::TransitiveClosure; | ||||||||||||||||||||||||||||
| 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 | # COMMENT THESE OUT FOR TESTING AND PRODUCTION. | ||||||||||||||||||||||||||||
| 7 | # $SIG{__DIE__ } = \&Graph::__carp_confess; | ||||||||||||||||||||||||||||
| 8 | # $SIG{__WARN__} = \&Graph::__carp_confess; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use base 'Graph'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Graph::TransitiveClosure::Matrix; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub _G () { Graph::_G() } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 75 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 75 | my ($class, $g, %opt) = @_; | |||||||||||||||||||||||||||
| 17 | 75 | ▶ | Graph::__carp_confess(__PACKAGE__."->new given non-Graph '$g'") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $g and $g->isa("Graph")
MC/DC0%0/2
ref $g and $g->isa("Graph")
ref $g
$g->isa("Graph")
Truth table33%1/3
A and B
A= ref $gB= $g->isa("Graph")
| |||||||||||||||||||||||||||||
| 18 | if !(ref $g and $g->isa('Graph')); | ||||||||||||||||||||||||||||
| 19 | 75 | ▶ | %opt = (path_vertices => 1) unless %opt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | # No delete $opt{ attribute_name } since we need to pass it on. | ||||||||||||||||||||||||||||
| 21 | 75 | ▶ | my $attr = exists $opt{ attribute_name } ? $opt{ attribute_name } : Graph::_defattr(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 75 | ▶ | $opt{ reflexive } = 1 unless exists $opt{ reflexive }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | my $tcg = $g->new( | ||||||||||||||||||||||||||||
| 24 | multiedged => 0, | ||||||||||||||||||||||||||||
| 25 | 75 | ▶ | ($opt{ reflexive } ? (vertices => [$g->vertices]) : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | 75 | my $tcm = $g->_check_cache('transitive_closure_matrix', [], | |||||||||||||||||||||||||||
| 28 | \&_transitive_closure_matrix_compute, %opt); | ||||||||||||||||||||||||||||
| 29 | 75 | my $tcm00 = $tcm->[0][0]; # 0=am, 0=bitmatrix | |||||||||||||||||||||||||||
| 30 | 75 | my $tcm01 = $tcm->[0][1]; # , 1=hash mapping v-name to the offset into dm data structures (in retval of $g->vertices) | |||||||||||||||||||||||||||
| 31 | 75 | my @edges; | |||||||||||||||||||||||||||
| 32 | 75 | for my $u ($tcm->vertices) { | |||||||||||||||||||||||||||
| 33 | 528 | my $tcm00i = $tcm00->[ $tcm01->{ $u } ]; | |||||||||||||||||||||||||||
| 34 | 528 | for my $v ($tcm->vertices) { | |||||||||||||||||||||||||||
| 35 | 18100 | ▶ | next if $u eq $v && ! $opt{ reflexive }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$u eq $v and not $opt{"reflexive"}
MC/DC100%2/2
$u eq $v and not $opt{"reflexive"}
$u eq $v
not $opt{"reflexive"}
Truth table100%3/3
A and not(B)
A= $u eq $vB= not $opt{"reflexive"}
| |||||||||||||||||||||||||||||
| 36 | 18088 | my $j = $tcm01->{ $v }; | |||||||||||||||||||||||||||
| 37 | 18088 | ▶ | push @edges, [$u, $v] if vec($tcm00i, $j, 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | # $tcm->is_transitive($u, $v) | ||||||||||||||||||||||||||||
| 39 | # $tcm->[0]->get($u, $v) | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 75 | $tcg->add_edges(@edges); | |||||||||||||||||||||||||||
| 43 | 75 | $tcg->set_graph_attribute('_tcm', [ $g->[ _G ], $tcm ]); | |||||||||||||||||||||||||||
| 44 | 75 | bless $tcg, $class; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 60 | ▶ | sub _transitive_closure_matrix_compute { | ||||||||||||||||||||||||||
|
Subroutine
_transitive_closure_matrix_compute: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 60 | Graph::TransitiveClosure::Matrix->new(@_); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 10 | ▶ | sub is_transitive { | ||||||||||||||||||||||||||
|
Subroutine
is_transitive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 10 | my $g = shift; | |||||||||||||||||||||||||||
| 53 | 10 | $g->expect_no_args(@_); | |||||||||||||||||||||||||||
| 54 | 10 | Graph::TransitiveClosure::Matrix::is_transitive($g); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 13295 | ▶ | sub transitive_closure_matrix { | ||||||||||||||||||||||||||
|
Subroutine
transitive_closure_matrix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 13295 | $_[0]->get_graph_attribute('_tcm')->[1]; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 6 | 1; | |||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||