Kneser.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
« Keller.pm ↑ Summary KnightGrid.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::Kneser;
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 = 16;
26 @ISA = ('Graph::Maker');
27  
28 # uncomment this to run the ### lines
29 # use Smart::Comments;
30  
31 use Graph::Maker::Johnson;
32  
33 sub init {
34 my ($self, %params) = @_;
35  
36 my $N = delete($params{'N'}) || 0;
37 my $K = delete($params{'K'}) || 0;
38 ### $N
39 ### $K
40 my $graph = Graph::Maker::Johnson::_make_graph(\%params);
41  
42 $graph->set_graph_attribute (name => "Kneser $N,$K");
43 my $directed = $graph->is_directed;
44  
45 my @vertices = Graph::Maker::Johnson::_N_K_subsets($N,$K);
46 foreach my $v (@vertices) {
47 $graph->add_vertex(join(',',@$v));
48 }
49  
50 my $add_edge = ($graph->is_directed ? 'add_cycle' : 'add_edge');
51 foreach my $i_from (0 .. $#vertices-1) {
52 my $from = $vertices[$i_from];
53 foreach my $i_to ($i_from+1 .. $#vertices) {
54 my $to = $vertices[$i_to];
55 ### consider: "from=".join(',',@$from)." to=".join(',',@$to)
56  
57 my $count = Graph::Maker::Johnson::_sorted_arefs_count_same($from, $to);
58 ### $count
59 if ($count == 0) {
60 my $v_from = join(',',@$from);
61 my $v_to = join(',',@$to);
62 ### edge: "$v_from to $v_to"
63 $graph->$add_edge($v_from, $v_to);
64 }
65 }
66 }
67 return $graph;
68 }
69  
70 Graph::Maker->add_factory_type('Kneser' => __PACKAGE__);
71 1;
72  
73 __END__
« Keller.pm ↑ Summary KnightGrid.pm »