| 1 | # Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021 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::Keller; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | $VERSION = 19; | |||||||||||||||||||||||||||
| 26 | 1 | @ISA = ('Graph::Maker'); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 14 | ▶ | sub _default_graph_maker { | ||||||||||||||||||||||||||
|
Subroutine
_default_graph_maker: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 14 | require Graph; | |||||||||||||||||||||||||||
| 31 | 14 | Graph->new(@_); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 22385 | ▶ | sub _is_edge { | ||||||||||||||||||||||||||
|
Subroutine
_is_edge: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 35 | 22385 | my ($from,$to) = @_; | |||||||||||||||||||||||||||
| 36 | 22385 | my $diff = $from ^ $to; | |||||||||||||||||||||||||||
| 37 | 22385 | my $seen_two = 0; | |||||||||||||||||||||||||||
| 38 | 22385 | my $seen_any = 0; | |||||||||||||||||||||||||||
| 39 | 22385 | ▶ | while ($diff) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 63049 | my $digit = $diff & 3; | |||||||||||||||||||||||||||
| 41 | 63049 | ▶ | if ($digit) { $seen_any++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 63049 | ▶ | if ($digit == 2) { $seen_two++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 63049 | ▶ | if ($seen_any >= 2 && $seen_two) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$seen_any >= 2 and $seen_two
MC/DC100%2/2
$seen_any >= 2 and $seen_two
$seen_any >= 2
$seen_two
Truth table100%3/3
A and B
A= $seen_any >= 2B= $seen_two
| |||||||||||||||||||||||||||||
| 44 | 13550 | return 1; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 49499 | $diff >>= 2; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 8835 | return 0; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 14 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 14 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 14 | ▶ | my $N = delete($params{'N'}) || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{'N'} || 0
MC/DC100%1/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table100%2/2
A
A= delete $params{'N'}
| |||||||||||||||||||||||||||||
| 55 | 14 | ▶ | my $subgraph = delete($params{'subgraph'}) || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{'subgraph'} || 0
MC/DC100%1/1
delete $params{'subgraph'} || 0
delete $params{'subgraph'}
Truth table100%2/2
A
A= delete $params{'subgraph'}
| |||||||||||||||||||||||||||||
| 56 | 14 | ▶ | my $graph_maker = delete($params{'graph_maker'}) || \&_default_graph_maker; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'graph_maker'} || \&Graph::Maker::Keller::_default_graph_maker
MC/DC0%0/1
delete $params{'graph_maker'} || \&Graph::Maker::Keller::_default_graph_maker
delete $params{'graph_maker'}
Truth table50%1/2
A
A= delete $params{'graph_maker'}
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 14 | my $graph = $graph_maker->(%params); | |||||||||||||||||||||||||||
| 59 | 14 | ▶ | my $add_edge = ($graph->is_directed ? 'add_cycle' : 'add_edge'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 14 | ▶ | if ($subgraph) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 7 | $graph->set_graph_attribute (name => "Keller Subgraph $N"); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 7 | my @vertices; | |||||||||||||||||||||||||||
| 65 | 7 | foreach my $to (1 .. (1 << (2*$N))-1) { | |||||||||||||||||||||||||||
| 66 | 414 | ▶ | if (_is_edge(0,$to)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 249 | $graph->add_vertex($to); | |||||||||||||||||||||||||||
| 68 | 249 | push @vertices, $to; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 7 | foreach my $i (0 .. $#vertices) { | |||||||||||||||||||||||||||
| 72 | 249 | my $from = $vertices[$i]; | |||||||||||||||||||||||||||
| 73 | 249 | foreach my $j ($i+1 .. $#vertices) { | |||||||||||||||||||||||||||
| 74 | 15677 | my $to = $vertices[$j]; | |||||||||||||||||||||||||||
| 75 | 15677 | ▶ | if (_is_edge($from,$to)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 9957 | $graph->$add_edge($from, $to); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||
| 82 | 7 | $graph->set_graph_attribute (name => "Keller $N"); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 7 | my $max_vertex = (1 << (2*$N)) - 1; | |||||||||||||||||||||||||||
| 85 | 7 | for my $from (0 .. $max_vertex) { | |||||||||||||||||||||||||||
| 86 | 229 | $graph->add_vertex($from); # for $N < 2 where there are no edges | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 229 | for my $to ($from+1 .. $max_vertex) { | |||||||||||||||||||||||||||
| 89 | 6294 | ▶ | if (_is_edge($from,$to)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 3344 | $graph->$add_edge($from, $to); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 14 | return $graph; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | Graph::Maker->add_factory_type('Keller' => __PACKAGE__); | |||||||||||||||||||||||||||
| 99 | 1 | 1; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # for (my($i,$imask) = (0,1); | ||||||||||||||||||||||||||||
| 106 | # $i < $N; | ||||||||||||||||||||||||||||
| 107 | # $i++, $imask <<= 2) { | ||||||||||||||||||||||||||||
| 108 | # foreach my $ixor ($imask, 2*$imask, 3*$imask) { | ||||||||||||||||||||||||||||
| 109 | # my $in = $n ^ $ixor; | ||||||||||||||||||||||||||||
| 110 | # | ||||||||||||||||||||||||||||
| 111 | # for (my($j,$jmask) = (0,2); | ||||||||||||||||||||||||||||
| 112 | # $j < $N; | ||||||||||||||||||||||||||||
| 113 | # $j++, $jmask <<= 2) { | ||||||||||||||||||||||||||||
| 114 | # next if $i == $j; | ||||||||||||||||||||||||||||
| 115 | # | ||||||||||||||||||||||||||||
| 116 | # my $n2 = $in ^ $jmask; | ||||||||||||||||||||||||||||
| 117 | # if ($directed || $n2 > $n) { | ||||||||||||||||||||||||||||
| 118 | # $graph->add_edge($n, $n2); | ||||||||||||||||||||||||||||
| 119 | # } | ||||||||||||||||||||||||||||
| 120 | # } | ||||||||||||||||||||||||||||
| 121 | # } | ||||||||||||||||||||||||||||
| 122 | # } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||