HalvedHypercube.pm

filter: Statementstmt 87.8% 36 / 41 Branchbran 87.5% 7 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 1 totaltotal 80.3% 49 / 61 CC 9 SCAR 16.5
CC
9
Cov
84%
init
8.0
_make_graph
6.0
_default_graph_maker
2.0
CRAP 5.2
« Kneser.pm ↑ Summary RookGrid.pm »
1 # Copyright 2022 Kevin Ryde
2 #
3 # This file is part of Graph-Maker-Other.
4 #
5 # This file is free software; you can redistribute it and/or modify it
6 # under 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 # This file is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Graph-Maker-Other. See the file COPYING. If not, see
17 # <http://www.gnu.org/licenses/>.
18  
19 package Graph::Maker::HalvedHypercube;
20 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Graph::Maker;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Graph::Maker::Hypercube;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use vars '$VERSION','@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 $VERSION = 19;
27 1 @ISA = ('Graph::Maker');
28  
29 # uncomment this to run the ### lines
30 # use Smart::Comments;
31  
32  
33 0 ▶sub _default_graph_maker {
Subroutine _default_graph_maker: not called CC=1 SCAR=6.9
34 0 require Graph;
35 0 Graph->new(@_);
36 }
37 0 ▶sub _make_graph {
Subroutine _make_graph: not called CC=2 SCAR=17.9
38 0 my ($params) = @_;
39 0 ▶ my $graph_maker = delete($params->{'graph_maker'}) || \&_default_graph_maker;
Condition0%0/2
delete $params->{'graph_maker'} || \&Graph::Maker::HalvedHypercube::_default_graph_maker
l!l
00
MC/DC0%0/1
delete $params->{'graph_maker'} || \&Graph::Maker::HalvedHypercube::_default_graph_maker
delete $params->{'graph_maker'}
Truth table0%0/2
A
A= delete $params->{'graph_maker'}
Aresult
11
00
40 0 return $graph_maker->(%$params);
41 }
42  
43 21 ▶sub init {
Subroutine init: called CC=8 SCAR=20.8
Pod undocumented
44 21 my ($self, %params) = @_;
45 21 my $N = delete($params{'N'});
46  
47 # decrement to make N-1 half cube
48 21 ▶ if ($N) { $N--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($N) 18 3 21
49 21 my $graph = Graph::Maker->new('hypercube', %params, N => $N);
50  
51 # Graph::Maker::Hypercube in its version 0.01 has N=0 as empty instead
52 # of 2^0=1 vertices. Ensure vertex 1 in this case.
53 21 $graph->add_vertex(1);
54  
55 21 ▶ if ($N > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($N > 1) 12 9 21
56 12 ▶ my $add = $graph->is_directed ? 'add_cycle' : 'add_edge';
Branch: 1 branch
BranchTrueFalseTotal
$graph->is_directed ? : 0 12 12
57 12 my $num_vertices = 1 <<$N;
58 12 my $directed = $graph->is_directed;
59 12 foreach my $from (1 .. $num_vertices) {
60 180 foreach my $i (1 .. $N-1) { # bit position
61 588 my $ito = ($from-1) ^ (1<<$i);
62 588 ▶ next if $ito < $from; # one way around only
Branch: 1 branch
BranchTrueFalseTotal
if $ito < $from 294 294 588
63 294 foreach my $j (0 .. $i-1) { # bit position
64 666 my $to = ($ito ^ (1<<$j)) + 1;
65 ### edge: "$from to $to"
66 # printf "%0*b\n", $N, $from-1;
67 # printf "%0*b\n\n", $N, $to-1;
68 666 $graph->$add ($from, $to);
69 }
70 }
71 }
72 }
73 21 return $graph;
74 }
75  
76 1 Graph::Maker->add_factory_type('halved_hypercube' => __PACKAGE__);
77 1 1;
78  
79 __END__
« Kneser.pm ↑ Summary RookGrid.pm »