| 1 | # Copyright 2015, 2016, 2017 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # This file is part of Graph-Graph6. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Graph-Graph6 is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 6 | # the terms of the GNU General Public License as published by the Free | ||||||||||||||||||||||||||||
| 7 | # Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Graph-Graph6 is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||||||||||||||||||
| 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||||||||||||||||||||||||
| 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||||||||||||||||||||||||||||
| 13 | # more details. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 16 | # with Graph-Graph6. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | package Graph::Reader::Graph6; | ||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use 5.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Graph::Reader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use vars '@ISA','$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | @ISA = ('Graph::Reader'); | |||||||||||||||||||||||||||
| 26 | 1 | $VERSION = 8; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Graph::Graph6; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Not using the base class read_graph() since want Graph->new to follow the | ||||||||||||||||||||||||||||
| 32 | # directed-ness of the format read. | ||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||
| 34 | # This misses the Graph::Reader::read_graph() warn() on unable to open file, | ||||||||||||||||||||||||||||
| 35 | # but think something in the return would be better than a warn message | ||||||||||||||||||||||||||||
| 36 | # anyway. | ||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||
| 38 | sub read_graph { | ||||||||||||||||||||||||||||
| 39 | 6 | ▶ | my ($self, $filename_or_fh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
read_graph: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 6 | require Graph; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 6 | my $width = 1; | |||||||||||||||||||||||||||
| 43 | # this vertex_name_func not a documented feature yet ... | ||||||||||||||||||||||||||||
| 44 | my $vertex_name_func = $self->{'vertex_name_func'} | ||||||||||||||||||||||||||||
| 45 | || sub { | ||||||||||||||||||||||||||||
| 46 | 48 | ▶ | my ($n) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 48 | return sprintf '%0*d', $width, $n; | |||||||||||||||||||||||||||
| 48 | 6 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'vertex_name_func'} || sub {
my($n) = @_;
return sprintf('%0*d', $width, $n);
}
MC/DC0%0/2
$self->{'vertex_name_func'} || sub {
my($n) = @_;
return sprintf('%0*d', $width, $n);
}
$self->{'vertex_name_func'}
sub {
my($n) = @_;
return sprintf('%0*d', $width, $n);
}
Truth table33%1/3
A || B
A= $self->{'vertex_name_func'}B= sub {
my($n) = @_;
return sprintf('%0*d', $width, $n);
}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 6 | my $graph; | |||||||||||||||||||||||||||
| 51 | my $check_countedged; | ||||||||||||||||||||||||||||
| 52 | 6 | ▶ | if (Graph::Graph6::read_graph | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 53 | ((ref $filename_or_fh ? 'fh' : 'filename') => $filename_or_fh, | ||||||||||||||||||||||||||||
| 54 | format_func => sub { | ||||||||||||||||||||||||||||
| 55 | 6 | ▶ | my ($format) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 6 | $graph = Graph->new(undirected => ($format ne 'digraph6')); | |||||||||||||||||||||||||||
| 57 | 6 | $check_countedged = ($format eq 'sparse6'); | |||||||||||||||||||||||||||
| 58 | }, | ||||||||||||||||||||||||||||
| 59 | num_vertices_func => sub { | ||||||||||||||||||||||||||||
| 60 | 6 | ▶ | my ($n) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 61 | 6 | $width = length($n-1); | |||||||||||||||||||||||||||
| 62 | 6 | foreach my $i (0 .. $n-1) { | |||||||||||||||||||||||||||
| 63 | 20 | my $name = $vertex_name_func->($i); | |||||||||||||||||||||||||||
| 64 | 20 | $graph->add_vertex($name); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||
| 67 | edge_func => sub { | ||||||||||||||||||||||||||||
| 68 | 14 | ▶ | my ($from, $to) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 69 | 14 | $from = $vertex_name_func->($from); | |||||||||||||||||||||||||||
| 70 | 14 | $to = $vertex_name_func->($to); | |||||||||||||||||||||||||||
| 71 | 14 | ▶ | if ($check_countedged && $graph->has_edge($from,$to)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$check_countedged and $graph->has_edge($from, $to)
MC/DC100%2/2
$check_countedged and $graph->has_edge($from, $to)
$check_countedged
$graph->has_edge($from, $to)
Truth table100%3/3
A and B
A= $check_countedgedB= $graph->has_edge($from, $to)
| |||||||||||||||||||||||||||||
| 72 | 2 | $graph = _countedged_copy($graph); | |||||||||||||||||||||||||||
| 73 | 2 | undef $check_countedged; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 14 | $graph->add_edge($from,$to); | |||||||||||||||||||||||||||
| 76 | })) { | ||||||||||||||||||||||||||||
| 77 | 6 | return $graph; | |||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||
| 79 | 0 | return 0; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # $graph is a Graph.pm. | ||||||||||||||||||||||||||||
| 84 | # Return a copy which is countedged. | ||||||||||||||||||||||||||||
| 85 | sub _countedged_copy { | ||||||||||||||||||||||||||||
| 86 | 2 | ▶ | my ($graph) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_countedged_copy: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 2 | my $new_graph = Graph->new (undirected => $graph->is_undirected, | |||||||||||||||||||||||||||
| 88 | countedged => 1); | ||||||||||||||||||||||||||||
| 89 | 2 | $new_graph->add_vertices($graph->vertices); | |||||||||||||||||||||||||||
| 90 | 2 | $new_graph->add_edges($graph->edges); | |||||||||||||||||||||||||||
| 91 | 2 | return $new_graph; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | 1; | |||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||