File Coverage

blib/lib/Graph/Maker/BiStar.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 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              
20             package Graph::Maker::BiStar;
21 1     1   596 use 5.004;
  1         3  
22 1     1   4 use strict;
  1         2  
  1         17  
23 1     1   108 use Graph::Maker;
  0            
  0            
24              
25             use vars '$VERSION','@ISA';
26             $VERSION = 8;
27             @ISA = ('Graph::Maker');
28              
29              
30             sub _default_graph_maker {
31             require Graph;
32             return Graph->new(@_);
33             }
34             sub _make_graph {
35             my ($params) = @_;
36             my $graph_maker = delete($params->{'graph_maker'}) || \&_default_graph_maker;
37             return $graph_maker->(%$params);
38             }
39              
40             sub init {
41             my ($self, %params) = @_;
42             my $N = delete($params{'N'}) || 0;
43             my $M = delete($params{'M'}) || 0;
44              
45             my $graph = _make_graph(\%params);
46             $graph->set_graph_attribute (name => "Bi-Star $N,$M");
47             my $directed = $graph->is_directed;
48             my $from = 1;
49             foreach my $size ($N, $M) {
50             next unless $size;
51             $graph->add_vertex($from);
52             foreach my $add (1 .. $size-1) {
53             $graph->add_edges($from, $from+$add,
54             ($directed ? ($from+$add, $from) : ()));
55             }
56             $from += $size;
57             }
58             if ($N && $M) {
59             $graph->add_edge (1, 1+$N);
60             }
61             return $graph;
62             }
63              
64             Graph::Maker->add_factory_type('bi_star' => __PACKAGE__);
65             1;
66              
67             __END__