File Coverage

blib/lib/Graph/Maker/Kneser.pm
Criterion Covered Total %
statement 6 8 75.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 9 11 81.8


line stmt bran cond sub pod time code
1             # Copyright 2015, 2016, 2017 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             # .
18              
19             package Graph::Maker::Kneser;
20 1     1   611 use 5.004;
  1         3  
21 1     1   4 use strict;
  1         2  
  1         20  
22 1     1   121 use Graph::Maker;
  0            
  0            
23              
24             use vars '$VERSION','@ISA';
25             $VERSION = 8;
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             foreach my $i_from (0 .. $#vertices-1) {
51             my $from = $vertices[$i_from];
52             foreach my $i_to ($i_from+1 .. $#vertices) {
53             my $to = $vertices[$i_to];
54             ### consider: "from=".join(',',@$from)." to=".join(',',@$to)
55              
56             my $count = Graph::Maker::Johnson::_sorted_arefs_count_same($from, $to);
57             ### $count
58             if ($count == 0) {
59             my $v_from = join(',',@$from);
60             my $v_to = join(',',@$to);
61             ### edge: "$v_from to $v_to"
62             $graph->add_edge($v_from, $v_to);
63             if ($directed) { $graph->add_edge($v_to, $v_from); }
64             }
65             }
66             }
67             return $graph;
68             }
69              
70             Graph::Maker->add_factory_type('Kneser' => __PACKAGE__);
71             1;
72              
73             __END__