| 1 | # Copyright 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 | |||||||||||||
| 20 | package Graph::Maker::ExcessConfigurations; | ||||||||||||
| 21 | 1 | ▶ | use 5.004; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 1 | ▶ | use List::Util 'sum'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 1 | ▶ | use Graph::Maker; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | |||||||||||||
| 26 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 1 | $VERSION = 19; | |||||||||||
| 28 | 1 | @ISA = ('Graph::Maker'); | |||||||||||
| 29 | |||||||||||||
| 30 | # uncomment this to run the ### lines | ||||||||||||
| 31 | # use Smart::Comments; | ||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 4 | ▶ | sub _default_graph_maker { | ||||||||||
|
Subroutine
_default_graph_maker: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | 4 | require Graph; | |||||||||||
| 36 | 4 | return Graph->new(@_); | |||||||||||
| 37 | } | ||||||||||||
| 38 | 4 | ▶ | sub _make_graph { | ||||||||||
|
Subroutine
_make_graph: called CC=2 SCAR=7.1
| |||||||||||||
| 39 | 4 | my ($params) = @_; | |||||||||||
| 40 | 4 | ▶ | my $graph_maker = delete($params->{'graph_maker'}) || \&_default_graph_maker; | ||||||||||
|
Condition50%1/2
delete $params->{'graph_maker'} || \&Graph::Maker::ExcessConfigurations::_default_graph_maker
MC/DC0%0/1
delete $params->{'graph_maker'} || \&Graph::Maker::ExcessConfigurations::_default_graph_maker
delete $params->{'graph_maker'}
Truth table50%1/2
A
A= delete $params->{'graph_maker'}
| |||||||||||||
| 41 | 4 | return $graph_maker->(%$params); | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 30 | ▶ | sub _step { | ||||||||||
|
Subroutine
_step: called CC=6 SCAR=17.9
| |||||||||||||
| 45 | 30 | my ($conf) = @_; | |||||||||||
| 46 | ### _step(): join(',',@$conf) | ||||||||||||
| 47 | 30 | my @ret; | |||||||||||
| 48 | { | ||||||||||||
| 49 | 30 | my @new_conf = @$conf; | |||||||||||
| 50 | 30 | $new_conf[0]++; # new r=1 | |||||||||||
| 51 | 30 | push @ret, \@new_conf; | |||||||||||
| 52 | ### incr bicyclic: join(',',@new_conf) | ||||||||||||
| 53 | } | ||||||||||||
| 54 | 30 | foreach my $i (0 .. $#$conf) { | |||||||||||
| 55 | 50 | ▶ | if ($conf->[$i]) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | { | ||||||||||||
| 57 | 31 | my @new_conf = @$conf; | |||||||||||
| 58 | 31 | $new_conf[$i]--; # raise r to r+1 | |||||||||||
| 59 | 31 | $new_conf[$i+1]++; | |||||||||||
| 60 | 31 | push @ret, \@new_conf; | |||||||||||
| 61 | ### raise: "i=$i to ".join(',',@new_conf) | ||||||||||||
| 62 | } | ||||||||||||
| 63 | 31 | foreach my $j ($i .. $#$conf) { | |||||||||||
| 64 | 37 | ▶ | if ($conf->[$j] > ($i==$j)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 15 | my @new_conf = @$conf; | |||||||||||
| 66 | 15 | $new_conf[$i]--; | |||||||||||
| 67 | 15 | $new_conf[$j]--; | |||||||||||
| 68 | 15 | my $t = $i+$j+2; | |||||||||||
| 69 | 15 | ▶ | while ($#new_conf < $t) { push @new_conf, 0; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 15 | $new_conf[$t]++; | |||||||||||
| 71 | 15 | push @ret, \@new_conf; | |||||||||||
| 72 | ### join: "i=$i j=$j to ".join(',',@new_conf) | ||||||||||||
| 73 | } | ||||||||||||
| 74 | } | ||||||||||||
| 75 | } | ||||||||||||
| 76 | } | ||||||||||||
| 77 | 30 | return @ret; | |||||||||||
| 78 | } | ||||||||||||
| 79 | # i=0 is r=1 | ||||||||||||
| 80 | # GP-Test i+1 + j+1 + 1 - 1 == i+j+2 | ||||||||||||
| 81 | |||||||||||||
| 82 | 1 | my %compositions_to_end = (0 => 1, | |||||||||||
| 83 | append => 1, | ||||||||||||
| 84 | prepend => 0); | ||||||||||||
| 85 | 4 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 86 | 4 | my ($self, %params) = @_; | |||||||||||
| 87 | ### ExcessConfigurations init ... | ||||||||||||
| 88 | |||||||||||||
| 89 | 4 | ▶ | my $N = delete($params{'N'}) || 0; | ||||||||||
|
Condition50%1/2
delete $params{'N'} || 0
MC/DC0%0/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table50%1/2
A
A= delete $params{'N'}
| |||||||||||||
| 90 | |||||||||||||
| 91 | 4 | my $graph = _make_graph(\%params); | |||||||||||
| 92 | 4 | $graph->set_graph_attribute | |||||||||||
| 93 | (name => "Excess Configurations N=$N"); | ||||||||||||
| 94 | |||||||||||||
| 95 | 4 | my @pending = ([0]); | |||||||||||
| 96 | 4 | $graph->add_vertex('0'); | |||||||||||
| 97 | 4 | foreach (1 .. $N) { | |||||||||||
| 98 | ### $_ | ||||||||||||
| 99 | 16 | my @new_pending; | |||||||||||
| 100 | 16 | foreach my $from (@pending) { | |||||||||||
| 101 | 30 | my $from_str = join(',',@$from); | |||||||||||
| 102 | 30 | foreach my $to (_step($from)) { | |||||||||||
| 103 | 76 | my $to_str = join(',',@$to); | |||||||||||
| 104 | 76 | ▶ | unless ($graph->has_vertex($to_str)) { push @new_pending, $to; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 76 | $graph->add_edge($from_str,$to_str); | |||||||||||
| 106 | } | ||||||||||||
| 107 | } | ||||||||||||
| 108 | 16 | @pending = @new_pending; | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | ### total vertices: scalar $graph->vertices | ||||||||||||
| 112 | ### total edges : scalar $graph->edges | ||||||||||||
| 113 | |||||||||||||
| 114 | 4 | return $graph; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 1 | Graph::Maker->add_factory_type('excess_configurations' => __PACKAGE__); | |||||||||||
| 118 | 1 | 1; | |||||||||||
| 119 | |||||||||||||
| 120 | __END__ | ||||||||||||