Keller.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Johnson.pm ↑ Summary Kneser.pm »
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=2.6
23  
24 use vars '$VERSION','@ISA';
25 $VERSION = 17;
26 @ISA = ('Graph::Maker');
27  
28  
29 sub _default_graph_maker {
30 require Graph;
31 Graph->new(@_);
32 }
33  
34 sub _is_edge {
35 my ($from,$to) = @_;
36 my $diff = $from ^ $to;
37 my $seen_two = 0;
38 my $seen_any = 0;
39 while ($diff) {
40 my $digit = $diff & 3;
41 if ($digit) { $seen_any++; }
42 if ($digit == 2) { $seen_two++; }
43 if ($seen_any >= 2 && $seen_two) {
44 return 1;
45 }
46 $diff >>= 2;
47 }
48 return 0;
49 }
50  
51 sub init {
52 my ($self, %params) = @_;
53  
54 my $N = delete($params{'N'}) || 0;
55 my $subgraph = delete($params{'subgraph'}) || 0;
56 my $graph_maker = delete($params{'graph_maker'}) || \&_default_graph_maker;
57  
58 my $graph = $graph_maker->(%params);
59 my $add_edge = ($graph->is_directed ? 'add_cycle' : 'add_edge');
60  
61 if ($subgraph) {
62 $graph->set_graph_attribute (name => "Keller Subgraph $N");
63  
64 my @vertices;
65 foreach my $to (1 .. (1 << (2*$N))-1) {
66 if (_is_edge(0,$to)) {
67 $graph->add_vertex($to);
68 push @vertices, $to;
69 }
70 }
71 foreach my $i (0 .. $#vertices) {
72 my $from = $vertices[$i];
73 foreach my $j ($i+1 .. $#vertices) {
74 my $to = $vertices[$j];
75 if (_is_edge($from,$to)) {
76 $graph->$add_edge($from, $to);
77 }
78 }
79 }
80  
81 } else {
82 $graph->set_graph_attribute (name => "Keller $N");
83  
84 my $max_vertex = (1 << (2*$N)) - 1;
85 for my $from (0 .. $max_vertex) {
86 $graph->add_vertex($from); # for $N < 2 where there are no edges
87  
88 for my $to ($from+1 .. $max_vertex) {
89 if (_is_edge($from,$to)) {
90 $graph->$add_edge($from, $to);
91 }
92 }
93 }
94 }
95 return $graph;
96 }
97  
98 Graph::Maker->add_factory_type('Keller' => __PACKAGE__);
99 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__
« Johnson.pm ↑ Summary Kneser.pm »