| 1 | package Graph::MoreUtils::Smooth; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Generate smoothed graphs | ||||||||||||||||||||||||||||||||||||
| 4 | 9 | our $VERSION = '0.3.0'; # VERSION | |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Graph::MoreUtils::Smooth::Intermediate; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Graph::Undirected; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | sub smooth | ||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
smooth: called CC=14 SCAR=29.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 15 | 3 | my( $graph ) = @_; | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | if( !blessed $graph || !$graph->isa( Graph::Undirected:: ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($graph) and $graph->isa("Graph::Undirected")
MC/DC0%0/2
builtin::blessed($graph) and $graph->isa("Graph::Undirected")
builtin::blessed($graph)
$graph->isa("Graph::Undirected")
Truth table33%1/3
A and B
A= builtin::blessed($graph)B= $graph->isa("Graph::Undirected")
| |||||||||||||||||||||||||||||||||||||
| 18 | 0 | die 'only Graph::Undirected and its derivatives are accepted' . "\n"; | |||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 3 | for ($graph->vertices) { | |||||||||||||||||||||||||||||||||||
| 22 | 55 | ▶ | next unless $graph->degree( $_ ) == 2; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 23 | 51 | my( $a, $b ) = sort $graph->neighbours( $_ ); | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | # do not reduce cycles of three vertices: | ||||||||||||||||||||||||||||||||||||
| 26 | 51 | ▶ | next if $graph->has_edge( $a, $b ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | 48 | my $intermediate; | |||||||||||||||||||||||||||||||||||
| 29 | 48 | ▶ | if( $graph->has_edge_attribute( $a, $_, 'intermediate' ) && | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$graph->has_edge_attribute($a, $_, "intermediate") and $graph->has_edge_attribute($b, $_, "intermediate")
MC/DC0%0/2
$graph->has_edge_attribute($a, $_, "intermediate") and $graph->has_edge_attribute($b, $_, "intermediate")
$graph->has_edge_attribute($a, $_, "intermediate")
$graph->has_edge_attribute($b, $_, "intermediate")
Truth table66%2/3
A and B
A= $graph->has_edge_attribute($a, $_, "intermediate")B= $graph->has_edge_attribute($b, $_, "intermediate")
| |||||||||||||||||||||||||||||||||||||
| 30 | $graph->has_edge_attribute( $b, $_, 'intermediate' ) ) { | ||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $intermediate = Graph::MoreUtils::Smooth::Intermediate->new( | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 32 | $_ lt $a | ||||||||||||||||||||||||||||||||||||
| 33 | ? $graph->get_edge_attribute( $a, $_, 'intermediate' )->reverse | ||||||||||||||||||||||||||||||||||||
| 34 | : $graph->get_edge_attribute( $a, $_, 'intermediate' ), | ||||||||||||||||||||||||||||||||||||
| 35 | $_, | ||||||||||||||||||||||||||||||||||||
| 36 | $_ gt $b | ||||||||||||||||||||||||||||||||||||
| 37 | ? $graph->get_edge_attribute( $b, $_, 'intermediate' )->reverse | ||||||||||||||||||||||||||||||||||||
| 38 | : $graph->get_edge_attribute( $b, $_, 'intermediate' ) ); | ||||||||||||||||||||||||||||||||||||
| 39 | } elsif( $graph->has_edge_attribute( $a, $_, 'intermediate' ) ) { | ||||||||||||||||||||||||||||||||||||
| 40 | 23 | $intermediate = $graph->get_edge_attribute( $a, $_, 'intermediate' ); | |||||||||||||||||||||||||||||||||||
| 41 | 23 | ▶ | $intermediate->reverse if $a gt $_; # getting natural order | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 42 | 23 | push @$intermediate, $_; | |||||||||||||||||||||||||||||||||||
| 43 | } elsif( $graph->has_edge_attribute( $b, $_, 'intermediate' ) ) { | ||||||||||||||||||||||||||||||||||||
| 44 | 23 | $intermediate = $graph->get_edge_attribute( $b, $_, 'intermediate' ); | |||||||||||||||||||||||||||||||||||
| 45 | 23 | ▶ | $intermediate->reverse if $_ gt $b; # getting natural order | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 46 | 23 | unshift @$intermediate, $_; | |||||||||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||||||||||
| 48 | 2 | $intermediate = Graph::MoreUtils::Smooth::Intermediate->new( $_ ); | |||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||
| 51 | 48 | $graph->delete_vertex( $_ ); | |||||||||||||||||||||||||||||||||||
| 52 | 48 | $graph->set_edge_attribute( $a, $b, 'intermediate', $intermediate ); | |||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | 3 | return $graph; | |||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | 9 | 1; | |||||||||||||||||||||||||||||||||||