| 1 | # Copyright 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 | |||||||||||||
| 20 | package Graph::Maker::QuartetTree; | ||||||||||||
| 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 Graph::Maker; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | |||||||||||||
| 25 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 1 | $VERSION = 19; | |||||||||||
| 27 | 1 | @ISA = ('Graph::Maker'); | |||||||||||
| 28 | |||||||||||||
| 29 | # uncomment this to run the ### lines | ||||||||||||
| 30 | # use Smart::Comments; | ||||||||||||
| 31 | |||||||||||||
| 32 | 16 | ▶ | sub _default_graph_maker { | ||||||||||
|
Subroutine
_default_graph_maker: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 16 | require Graph; | |||||||||||
| 34 | 16 | Graph->new(@_); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | # return $x,$y multiplied by 2+i | ||||||||||||
| 38 | # GP-Test (2+I)*(x+I*y) == (2*x-y) + (x+2*y)*I | ||||||||||||
| 39 | 24 | ▶ | sub _mul { | ||||||||||
|
Subroutine
_mul: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | 24 | my ($x,$y) = @_; | |||||||||||
| 41 | 24 | return (2*$x - $y, | |||||||||||
| 42 | $x + 2*$y); | ||||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 928 | ▶ | sub _xy_rotate_plus90 { | ||||||||||
|
Subroutine
_xy_rotate_plus90: called CC=2 SCAR=6.9
| |||||||||||||
| 46 | 928 | my ($x,$y, $multiple) = @_; | |||||||||||
| 47 | 928 | $multiple %= 4; | |||||||||||
| 48 | 928 | foreach (1 .. $multiple) { | |||||||||||
| 49 | 1064 | ($x,$y) = (-$y,$x); # rotate +90 | |||||||||||
| 50 | } | ||||||||||||
| 51 | 928 | return ($x,$y); | |||||||||||
| 52 | } | ||||||||||||
| 53 | # @ E | ||||||||||||
| 54 | # < | | ||||||||||||
| 55 | # v | ||||||||||||
| 56 | # S---->*---->* @ expand on right | ||||||||||||
| 57 | # v v ^ | ||||||||||||
| 58 | # | ^ | ||||||||||||
| 59 | # @ *---->* @ | ||||||||||||
| 60 | # v | ||||||||||||
| 61 | # | ||||||||||||
| 62 | # *---->* S @ | ||||||||||||
| 63 | # v | ||||||||||||
| 64 | |||||||||||||
| 65 | 16 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 66 | 16 | my ($self, %params) = @_; | |||||||||||
| 67 | |||||||||||||
| 68 | 16 | ▶ | my $level = delete($params{'level'}) || 0; | ||||||||||
|
Condition100%2/2
delete $params{'level'} || 0
MC/DC100%1/1
delete $params{'level'} || 0
delete $params{'level'}
Truth table100%2/2
A
A= delete $params{'level'}
| |||||||||||||
| 69 | 16 | ▶ | my $vertex_names = delete($params{'vertex_names'}) || 'xy'; | ||||||||||
|
Condition50%1/2
delete $params{'vertex_names'} || 'xy'
MC/DC0%0/1
delete $params{'vertex_names'} || 'xy'
delete $params{'vertex_names'}
Truth table50%1/2
A
A= delete $params{'vertex_names'}
| |||||||||||||
| 70 | 16 | ▶ | my $graph_maker = delete($params{graph_maker}) || \&_default_graph_maker; | ||||||||||
|
Condition50%1/2
delete $params{'graph_maker'} || \&Graph::Maker::QuartetTree::_default_graph_maker
MC/DC0%0/1
delete $params{'graph_maker'} || \&Graph::Maker::QuartetTree::_default_graph_maker
delete $params{'graph_maker'}
Truth table50%1/2
A
A= delete $params{'graph_maker'}
| |||||||||||||
| 71 | |||||||||||||
| 72 | 16 | my $graph = $graph_maker->(%params); | |||||||||||
| 73 | 16 | $graph->set_graph_attribute (name => "Quartet Tree $level"); | |||||||||||
| 74 | 16 | $graph->set_graph_attribute (vertex_name_type_xy => 1); | |||||||||||
| 75 | |||||||||||||
| 76 | 16 | my @ex = (1); | |||||||||||
| 77 | 16 | my @ey = (0); | |||||||||||
| 78 | 16 | foreach (1 .. $level) { | |||||||||||
| 79 | 24 | my ($ex,$ey) = _mul($ex[-1],$ey[-1]); | |||||||||||
| 80 | 24 | push @ex, $ex; | |||||||||||
| 81 | 24 | push @ey, $ey; | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | 16 | my $straight = ($vertex_names =~ /straight/); | |||||||||||
| 85 | 16 | ▶ | my $add_edge = ($graph->is_directed ? 'add_cycle' : 'add_edge'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 16 | my $recurse; | |||||||||||
| 87 | 776 | ▶ | $recurse = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||
| 88 | 776 | my ($x,$y, $dir, $k) = @_; | |||||||||||
| 89 | ### recurse: "$x,$y dir=$dir k=$k" | ||||||||||||
| 90 | ### assert: $k >= 0 | ||||||||||||
| 91 | 776 | ▶ | if ($k == 0) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 624 | my $from = "$x,$y"; | |||||||||||
| 93 | 624 | my ($dx,$dy) = _xy_rotate_plus90(1,0, $dir); | |||||||||||
| 94 | 624 | $x += $dx; | |||||||||||
| 95 | 624 | $y += $dy; | |||||||||||
| 96 | 624 | my $to = "$x,$y"; | |||||||||||
| 97 | 624 | $graph->$add_edge($from,$to); | |||||||||||
| 98 | } else { | ||||||||||||
| 99 | 152 | $k--; | |||||||||||
| 100 | 152 | my $dx = $ex[$k]; | |||||||||||
| 101 | 152 | my $dy = $ey[$k]; | |||||||||||
| 102 | 152 | ($dx,$dy) = _xy_rotate_plus90($dx,$dy, $dir); | |||||||||||
| 103 | 152 | my ($lx,$ly) = _xy_rotate_plus90($dx,$dy, 1); | |||||||||||
| 104 | 152 | $recurse->($x, $y, $dir, $k); | |||||||||||
| 105 | 152 | $recurse->($x+$dx, $y+$dy, $dir, $k); | |||||||||||
| 106 | 152 | $recurse->($x+2*$dx-$lx, $y+2*$dy-$ly, $dir+1, $k); | |||||||||||
| 107 | 152 | ▶ | if ($straight) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | 0 | $recurse->($x+2*$dx+2*$lx, $y+2*$dy+2*$ly, $dir+1, $k); | |||||||||||
| 109 | } else { | ||||||||||||
| 110 | 152 | $recurse->($x+$dx-$lx, $y+$dy-$ly, $dir, $k); | |||||||||||
| 111 | } | ||||||||||||
| 112 | 152 | $recurse->($x+2*$dx+$lx, $y+2*$dy+$ly, $dir-1, $k); | |||||||||||
| 113 | } | ||||||||||||
| 114 | 16 | }; | |||||||||||
| 115 | 16 | $recurse->(0,0, 0, $level); | |||||||||||
| 116 | |||||||||||||
| 117 | 16 | return $graph; | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | 1 | Graph::Maker->add_factory_type('quartet_tree' => __PACKAGE__); | |||||||||||
| 121 | 1 | 1; | |||||||||||
| 122 | |||||||||||||
| 123 | __END__ | ||||||||||||