| 1 | package AI::Genetic::Pro; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 434 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 434 | $VERSION = 1.002; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #--------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 434 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 434 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 434 | ▶ | use base qw( Class::Accessor::Fast::XS ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 434 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 434 | ▶ | use Clone qw( clone ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 434 | ▶ | use Struct::Compare; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 434 | ▶ | use Digest::MD5 qw( md5_hex ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 434 | ▶ | use List::Util qw( sum ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 434 | ▶ | use List::MoreUtils qw( minmax first_index apply ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #use Data::Dumper; $Data::Dumper::Sortkeys = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 434 | ▶ | use Tie::Array::Packed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 434 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 434 | ▶ | use AI::Genetic::Pro::Array::Type qw( get_package_by_element_size ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 434 | ▶ | use AI::Genetic::Pro::Chromosome; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 434 | __PACKAGE__->mk_accessors(qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | mce | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | population | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | terminate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | chromosomes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | crossover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | native | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | parents _parents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | history _history | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | fitness _fitness _fitness_real | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | mutation _mutator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | strategy _strategist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | selection _selector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | _translations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | preserve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | variable_length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | _fix_range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | _package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | _length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | strict _strict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | workers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | _init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Additional modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 434 | ▶ | use constant STORABLE => 'Storable'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 434 | ▶ | use constant GD => 'GD::Graph::linespoints'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 434 | my $_Cache = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 434 | my $_temp_chromosome; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 824 | ▶ | my ( $class, %args ) = ( shift, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 824 | ▶ | my %opts = map { if(ref $_){$_}else{ /^-?(.*)$/o; $1 }} @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 824 | my $self = bless \%opts, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 824 | ▶ | $AI::Genetic::Pro::Array::Type::Native = 1 if $self->native; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 824 | ▶ | croak(q/Type of chromosomes cannot be "combination" if "variable length" feature is active!/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->type eq "combination" and $self->variable_length
MC/DC0%0/2
$self->type eq "combination" and $self->variable_length
$self->type eq "combination"
$self->variable_length
Truth table66%2/3
A and B
A= $self->type eq "combination"B= $self->variable_length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | if $self->type eq q/combination/ and $self->variable_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 824 | ▶ | croak(q/You must specify a crossover strategy with -strategy!/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | unless defined ($self->strategy); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 824 | ▶ | croak(q/Type of chromosomes cannot be "combination" if strategy is not one of: OX, PMX!/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$self->type eq "combination" and ($self->strategy->[0] ne "OX" and $self->strategy->[0] ne "PMX")
$self->strategy->[0] ne "OX" and $self->strategy->[0] ne "PMX"
MC/DC0%0/3
$self->type eq "combination" and ($self->strategy->[0] ne "OX" and $self->strategy->[0] ne "PMX")
$self->type eq "combination"
$self->strategy->[0] ne "OX"
$self->strategy->[0] ne "PMX"
Truth table50%2/4
A and B and C
A= $self->type eq "combination"B= $self->strategy->[0] ne "OX"C= $self->strategy->[0] ne "PMX"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | if $self->type eq q/combination/ and ($self->strategy->[0] ne q/OX/ and $self->strategy->[0] ne q/PMX/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 824 | ▶ | croak(q/Strategy cannot be "/,$self->strategy->[0],q/" if "variable length" feature is active!/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->strategy->[0] eq "PMX" || $self->strategy->[0] eq "OX" and $self->variable_length
$self->strategy->[0] eq "PMX" or $self->strategy->[0] eq "OX"
MC/DC0%0/3
$self->strategy->[0] eq "PMX" || $self->strategy->[0] eq "OX" and $self->variable_length
$self->strategy->[0] eq "PMX"
$self->strategy->[0] eq "OX"
$self->variable_length
Truth table40%2/5
A or B and C
A= $self->strategy->[0] eq "PMX"B= $self->strategy->[0] eq "OX"C= $self->variable_length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | if ($self->strategy->[0] eq 'PMX' or $self->strategy->[0] eq 'OX') and $self->variable_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 824 | ▶ | $self->_set_strict if $self->strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 824 | ▶ | return $self unless $self->mce; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 418 | delete $self->{ mce }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 418 | ▶ | 'AI::Genetic::Pro::MCE'->use or die q[Cannot raise multicore support: ] . $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 418 | return AI::Genetic::Pro::MCE->new( $self, \%args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub _Cache { $_Cache; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Cache: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # INIT ################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub _set_strict { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_strict: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # fitness | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $fitness = $self->fitness(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | my $replacement = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my @tmp = @{$_[1]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $ret = $fitness->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my @cmp = @{$_[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | die qq/Chromosome was modified in a fitness function from "@tmp" to "@{$_[1]}"!\n/ unless compare(\@tmp, \@cmp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->fitness($replacement); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | sub _fitness_cached { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 61432 | ▶ | my ($self, $chromosome) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fitness_cached: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | #my $key = md5_hex(${tied(@$chromosome)}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 61432 | ▶ | my $key = md5_hex( $self->_package ? md5_hex( ${ tied( @$chromosome ) } ) : join( q[:], @$chromosome ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 61432 | ▶ | return $_Cache->{$key} if exists $_Cache->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 12989 | $_Cache->{$key} = $self->_fitness_real->($self, $chromosome); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 12989 | return $_Cache->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | sub _init_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 822 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_cache: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 822 | $self->_fitness_real($self->fitness); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 822 | $self->fitness(\&_fitness_cached); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 822 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub _check_data_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | ▶ | my ($self, $data_org) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_data_ref: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | my $data = clone($data_org); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | my $ars; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | for(0..$#$data){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 48 | ▶ | next if $ars->{$data->[$_]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 48 | $ars->{$data->[$_]} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 48 | unshift @{$data->[$_]}, undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # we have to find C to (in some cases) incrase value of range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # due to design model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | sub _find_fix_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_fix_range: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | for my $idx (0..$#$data){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 24 | ▶ | if($data->[$idx]->[1] < 1){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 24 | my $const = 1 - $data->[$idx]->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 24 | push @{$self->_fix_range}, $const; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 24 | $data->[$idx]->[1] += $const; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 24 | $data->[$idx]->[2] += $const; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | }else{ push @{$self->_fix_range}, 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 824 | ▶ | my ( $self, $data ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=22 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 824 | ▶ | croak q/You have to pass some data to "init"!/ unless $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 824 | $self->generation(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 824 | $self->_init( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 824 | $self->_fitness( { } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 824 | $self->_fix_range( [ ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 824 | $self->_history( [ [ ], [ ], [ ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 824 | ▶ | $self->_init_cache if $self->cache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 824 | ▶ | if($self->type eq q/listvector/){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | croak(q/You have to pass array reference if "type" is set to "listvector"/) unless ref $data eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | $self->_translations( $self->_check_data_ref($data) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | }elsif($self->type eq q/bitvector/){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 817 | ▶ | croak(q/You have to pass integer if "type" is set to "bitvector"/) if $data !~ /^\d+$/o; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 817 | $self->_translations( [ [ 0, 1 ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 817 | $self->_translations->[$_] = $self->_translations->[0] for 1..$data-1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | }elsif($self->type eq q/combination/){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | ▶ | croak(q/You have to pass array reference if "type" is set to "combination"/) unless ref $data eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | $self->_translations( [ clone($data) ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | $self->_translations->[$_] = $self->_translations->[0] for 1..$#$data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | }elsif($self->type eq q/rangevector/){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | croak(q/You have to pass array reference if "type" is set to "rangevector"/) unless ref $data eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | $self->_translations( $self->_find_fix_range( $self->_check_data_ref($data) )); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | croak(q/You have to specify first "type" of vector!/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 824 | my $size = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 824 | ▶ | if($self->type ne q/rangevector/){ for(@{$self->_translations}){ $size = $#$_ if $#$_ > $size; } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # else{ for(@{$self->_translations}){ $size = $_->[1] if $_->[1] > $size; } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | ▶ | else{ for(@{$self->_translations}){ $size = $_->[2] if $_->[2] > $size; } } # Provisional patch for rangevector values truncated to signed 8-bit quantities. Thx to Tod Hagan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 824 | my $package = get_package_by_element_size($size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 824 | $self->_package($package); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 824 | ▶ | my $length = ref $data ? sub { $#$data; } : sub { $data - 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 824 | ▶ | if($self->variable_length){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | $length = ref $data ? sub { 1 + int( rand( $#{ $self->_init } ) ); } : sub { 1 + int( rand( $self->_init - 1) ); }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 824 | $self->_length( $length ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 824 | $self->chromosomes( [ ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2402 | push @{$self->chromosomes}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | AI::Genetic::Pro::Chromosome->new($self->_translations, $self->type, $package, $length->()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 824 | for 1..$self->population; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 824 | $self->_calculate_fitness_all(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # SAVE / LOAD ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | sub spew { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | STORABLE->use( qw( store retrieve freeze thaw ) ) or croak(q/You need "/.STORABLE.q/" module to save a state of "/.__PACKAGE__.q/"!/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spew: not called CC=5 SCAR=34.0
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $Storable::Deparse = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $Storable::Eval = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $clone = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | _selector => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | _strategist => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | _mutator => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $clone->{ chromosomes } = [ map { ${ tied( @$_ ) } } @{ $self->chromosomes } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | if $self->_package; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | foreach my $key(keys %$self){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | next if exists $clone->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $clone->{$key} = $self->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | return $clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | sub slurp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ( $self, $dump ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slurp: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if( my $typ = $self->_package ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | @{ $dump->{ chromosomes } } = map { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $arr = $typ->make_with_packed( $_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | bless $arr, q[AI::Genetic::Pro::Chromosome]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | } @{ $dump->{ chromosomes } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | %$self = %$dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my ( $self, $file ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | croak(q/You have to specify file!/) unless defined $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | store( $self->spew, $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | STORABLE->use( qw( store retrieve freeze thaw ) ) or croak(q/You need "/.STORABLE.q/" module to load a state of "/.__PACKAGE__.q/"!/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $Storable::Deparse = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $Storable::Eval = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | croak(q/You have to specify file!/) unless defined $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $clone = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | return carp('Incorrect file!') unless $clone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return $self->slurp( $clone ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # CHARTS ############################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | sub chart { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | GD->require or croak(q/You need "/.GD.q/" module to draw chart of evolution!/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chart: not called CC=17 SCAR=57.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($self, %params) = (shift, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my $graph = GD()->new(($params{-width} || 640), ($params{-height} || 480)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$params{'-width'} || 640
$params{'-height'} || 480
MC/DC0%0/1
$params{'-width'} || 640
$params{'-width'}
MC/DC0%0/1
$params{'-height'} || 480
$params{'-height'}
Truth table0%0/2
A
A= $params{'-width'}
Truth table0%0/2
A
A= $params{'-height'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $data = $self->getHistory; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if(defined $params{-font}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $graph->set_title_font ($params{-font}, 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $graph->set_x_label_font($params{-font}, 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $graph->set_y_label_font($params{-font}, 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $graph->set_legend_font ($params{-font}, 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | $graph->set_legend( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | $params{legend1} || q/Max value/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | $params{legend2} || q/Mean value/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | $params{legend3} || q/Min value/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$params{'legend1'} || 'Max value'
$params{'legend2'} || 'Mean value'
$params{'legend3'} || 'Min value'
MC/DC0%0/1
$params{'legend1'} || 'Max value'
$params{'legend1'}
MC/DC0%0/1
$params{'legend2'} || 'Mean value'
$params{'legend2'}
MC/DC0%0/1
$params{'legend3'} || 'Min value'
$params{'legend3'}
Truth table0%0/2
A
A= $params{'legend1'}
Truth table0%0/2
A
A= $params{'legend2'}
Truth table0%0/2
A
A= $params{'legend3'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | $graph->set( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | x_label_skip => int(($data->[0]->[-1]*4)/100), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | x_labels_vertical => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | x_label_position => .5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | y_label_position => .5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | y_long_ticks => 1, # poziome linie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | x_ticks => 1, # poziome linie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | l_margin => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | b_margin => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | r_margin => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | t_margin => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | show_values => (defined $params{-show_values} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | values_vertical => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | values_format => ($params{-format} || '%.2f'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | zero_axis => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | #interlaced => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | logo_position => 'BR', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | legend_placement => 'RT', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | bgclr => 'white', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | boxclr => '#FFFFAA', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | transparent => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | title => ($params{'-title'} || q/Evolution/ ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | x_label => ($params{'-x_label'} || q/Generation/), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | y_label => ($params{'-y_label'} || q/Value/ ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | ( $params{-logo} && -f $params{-logo} ? ( logo => $params{-logo} ) : ( ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/11
$params{'-format'} || '%.2f'
$params{'-title'} || 'Evolution'
$params{'-x_label'} || 'Generation'
$params{'-y_label'} || 'Value'
$params{"-logo"} and -f $params{"-logo"}
MC/DC0%0/1
$params{'-format'} || '%.2f'
$params{'-format'}
MC/DC0%0/1
$params{'-title'} || 'Evolution'
$params{'-title'}
MC/DC0%0/1
$params{'-x_label'} || 'Generation'
$params{'-x_label'}
MC/DC0%0/1
$params{'-y_label'} || 'Value'
$params{'-y_label'}
MC/DC0%0/2
$params{"-logo"} and -f $params{"-logo"}
$params{"-logo"}
-f $params{"-logo"}
Truth table0%0/2
A
A= $params{'-format'}
Truth table0%0/2
A
A= $params{'-title'}
Truth table0%0/2
A
A= $params{'-x_label'}
Truth table0%0/2
A
A= $params{'-y_label'}
Truth table0%0/3
A and B
A= $params{"-logo"}B= -f $params{"-logo"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | my $gd = $graph->plot( [ [ 0..$#{$data->[0]} ], @$data ] ) or croak($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | open(my $fh, '>', $params{-filename}) or croak($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | print $fh $gd->png; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # TRANSLATIONS ######################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | sub as_array_def_only { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | my ($self, $chromosome) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_array_def_only: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | return $self->as_array($chromosome) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->variable_length or $self->variable_length < 2
MC/DC0%0/2
not $self->variable_length or $self->variable_length < 2
not $self->variable_length
$self->variable_length < 2
Truth table0%0/3
not(A) or B
A= not $self->variable_lengthB= $self->variable_length < 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | if not $self->variable_length or $self->variable_length < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if( $self->type eq q/bitvector/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | return $self->as_array($chromosome); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $ar = $self->as_array($chromosome); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $idx = first_index { $_ } @$ar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my @array = @$ar[$idx..$#$chromosome]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | return @array if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return \@array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | sub as_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 23134 | ▶ | my ($self, $chromosome) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_array: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 23134 | ▶ | if($self->type eq q/bitvector/){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 20855 | ▶ | return @$chromosome if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 20855 | return $chromosome; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | }elsif($self->type eq q/rangevector/){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 959 | my $fix_range = $self->_fix_range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 959 | my $c = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | #my @array = map { $c++; warn "WARN: $c | ",scalar @$chromosome,"\n" if not defined $fix_range->[$c]; $_ ? $_ - $fix_range->[$c] : undef } @$chromosome; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 959 | ▶ | my @array = map { $c++; $_ ? $_ - $fix_range->[$c] : undef } @$chromosome; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 959 | ▶ | return @array if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 959 | return \@array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1320 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1320 | my @array = map { $self->_translations->[$cnt++]->[$_] } @$chromosome; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1320 | ▶ | return @array if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1320 | return \@array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | sub as_string_def_only { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | my ($self, $chromosome) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string_def_only: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | return $self->as_string($chromosome) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->variable_length or $self->variable_length < 2
MC/DC0%0/2
not $self->variable_length or $self->variable_length < 2
not $self->variable_length
$self->variable_length < 2
Truth table0%0/3
not(A) or B
A= not $self->variable_lengthB= $self->variable_length < 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | if not $self->variable_length or $self->variable_length < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $array = $self->as_array_def_only($chromosome); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | return join(q//, @$array) if $self->type eq q/bitvector/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return join(q/___/, @$array); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 414 | ▶ | return join(q//, @{$_[1]}) if $_[0]->type eq q/bitvector/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=3 SCAR=16.5
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | return join(q/___/, map { defined $_ ? $_ : q/ / } $_[0]->as_array($_[1])); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | sub as_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 23192 | ▶ | my ($self, $chromosome) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_value: called CC=8 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 23192 | ▶ | croak(q/You MUST call 'as_value' as method of 'AI::Genetic::Pro' object./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
defined $_[0] and ref $_[0] and ref $_[0] eq "AI::Genetic::Pro" || ref $_[0] eq "AI::Genetic::Pro::MCE"
defined $_[0] and ref $_[0]
ref $_[0] eq "AI::Genetic::Pro" or ref $_[0] eq "AI::Genetic::Pro::MCE"
MC/DC0%0/4
defined $_[0] and ref $_[0] and ref $_[0] eq "AI::Genetic::Pro" || ref $_[0] eq "AI::Genetic::Pro::MCE"
defined $_[0]
ref $_[0]
ref $_[0] eq "AI::Genetic::Pro"
ref $_[0] eq "AI::Genetic::Pro::MCE"
Truth table20%1/5
A and B and C or D
A= defined $_[0]B= ref $_[0]C= ref $_[0] eq "AI::Genetic::Pro"D= ref $_[0] eq "AI::Genetic::Pro::MCE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | unless defined $_[0] and ref $_[0] and ( ref $_[0] eq 'AI::Genetic::Pro' or ref $_[0] eq 'AI::Genetic::Pro::MCE'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 23192 | ▶ | croak(q/You MUST pass 'AI::Genetic::Pro::Chromosome' object to 'as_value' method./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $_[1] and ref $_[1] and ref $_[1] eq "AI::Genetic::Pro::Chromosome"
defined $_[1] and ref $_[1]
MC/DC0%0/3
defined $_[1] and ref $_[1] and ref $_[1] eq "AI::Genetic::Pro::Chromosome"
defined $_[1]
ref $_[1]
ref $_[1] eq "AI::Genetic::Pro::Chromosome"
Truth table25%1/4
A and B and C
A= defined $_[1]B= ref $_[1]C= ref $_[1] eq "AI::Genetic::Pro::Chromosome"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | unless defined $_[1] and ref $_[1] and ref $_[1] eq 'AI::Genetic::Pro::Chromosome'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 23192 | return $self->fitness->($self, $chromosome); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # ALGORITHM ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | sub _calculate_fitness_all { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 406 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calculate_fitness_all: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 406 | $self->_fitness( { } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | $self->_fitness->{$_} = $self->fitness()->($self, $self->chromosomes->[$_]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 406 | for 0..$#{$self->chromosomes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # sorting the population is not necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # my (@chromosomes, %fitness); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # for my $idx (sort { $self->_fitness->{$a} <=> $self->_fitness->{$b} } keys %{$self->_fitness}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # push @chromosomes, $self->chromosomes->[$idx]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # $fitness{$#chromosomes} = $self->_fitness->{$idx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # delete $self->_fitness->{$idx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # delete $self->chromosomes->[$idx]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # $self->_fitness(\%fitness); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # $self->chromosomes(\@chromosomes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 406 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | sub _select_parents { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 387 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_select_parents: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 387 | ▶ | unless($self->_selector){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 375 | ▶ | croak "You must specify a selection strategy!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | unless defined $self->selection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 375 | my @tmp = @{$self->selection}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 375 | my $selector = q/AI::Genetic::Pro::Selection::/ . shift @tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 375 | ▶ | $selector->require or die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 375 | $self->_selector($selector->new(@tmp)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 387 | $self->_parents($self->_selector->run($self)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 387 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | sub _crossover { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 387 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_crossover: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 387 | ▶ | unless($self->_strategist){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 375 | my @tmp = @{$self->strategy}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 375 | my $strategist = q/AI::Genetic::Pro::Crossover::/ . shift @tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 375 | ▶ | $strategist->require or die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 375 | $self->_strategist($strategist->new(@tmp)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 387 | my $a = $self->_strategist->run($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 387 | $self->chromosomes( $a ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 387 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | sub _mutation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 387 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mutation: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 387 | ▶ | unless($self->_mutator){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 375 | my $mutator = q/AI::Genetic::Pro::Mutation::/ . ucfirst(lc($self->type)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 375 | ▶ | unless($mutator->require){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $mutator = q/AI::Genetic::Pro::Mutation::Listvector/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $mutator->require; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 375 | $self->_mutator($mutator->new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 387 | return $self->_mutator->run($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | sub _save_history { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 3158 | ▶ | my @tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_save_history: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 3158 | ▶ | if($_[0]->history){ @tmp = $_[0]->getAvgFitness; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 3158 | else { @tmp = (undef, undef, undef); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 3158 | push @{$_[0]->_history->[0]}, $tmp[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 3158 | push @{$_[0]->_history->[1]}, $tmp[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 3158 | push @{$_[0]->_history->[2]}, $tmp[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 3158 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | sub inject { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 382 | ▶ | my ($self, $candidates) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inject: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 382 | for(@$candidates){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 13187 | push @{$self->chromosomes}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | AI::Genetic::Pro::Chromosome->new_from_data($self->_translations, $self->type, $self->_package, $_, $self->_fix_range); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 13187 | $self->_fitness->{$#{$self->chromosomes}} = $self->fitness()->($self, $self->chromosomes->[-1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 382 | $self->_strict( [ ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 382 | $self->population( $self->population + scalar( @$candidates ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 382 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | sub _state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 390 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_state: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 390 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 390 | ▶ | if( $self->_package ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | @res = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 182 | [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 1400 | ${ tied( @{ $self->chromosomes->[ $_ ] } ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1400 | $self->_fitness->{ $_ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } 0 .. $self->population - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | @res = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 208 | [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | $self->chromosomes->[ $_ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 1600 | $self->_fitness->{ $_ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } 0 .. $self->population - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 390 | return \@res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | sub evolve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 377 | ▶ | my ($self, $generations) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evolve: called CC=19 SCAR=44.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # generations must be defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 377 | ▶ | $generations ||= -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$generations ||= -1
MC/DC0%0/1
$generations ||= -1
$generations
Truth table50%1/2
A
A= $generations
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 377 | ▶ | if($self->strict and $self->_strict){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->strict and $self->_strict
MC/DC0%0/2
$self->strict and $self->_strict
$self->strict
$self->_strict
Truth table33%1/3
A and B
A= $self->strictB= $self->_strict
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | for my $idx (0..$#{$self->chromosomes}){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | croak(q/Chromosomes was modified outside the 'evolve' function!/) unless $self->chromosomes->[$idx] and $self->_strict->[$idx]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->chromosomes->[$idx] and $self->_strict->[$idx]
MC/DC0%0/2
$self->chromosomes->[$idx] and $self->_strict->[$idx]
$self->chromosomes->[$idx]
$self->_strict->[$idx]
Truth table0%0/3
A and B
A= $self->chromosomes->[$idx]B= $self->_strict->[$idx]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my @tmp0 = @{$self->chromosomes->[$idx]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my @tmp1 = @{$self->_strict->[$idx]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | croak(qq/Chromosome was modified outside the 'evolve' function from "@tmp0" to "@tmp1"!/) unless compare(\@tmp0, \@tmp1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # split into two loops just for speed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 377 | ▶ | unless($self->preserve){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 375 | ▶ | for(my $i = 0; $i != $generations; $i++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # terminate ---------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 398 | ▶ | last if $self->terminate and $self->terminate->($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->terminate and $self->terminate->($self)
MC/DC50%1/2
$self->terminate and $self->terminate->($self)
$self->terminate
$self->terminate->($self)
Truth table66%2/3
A and B
A= $self->terminateB= $self->terminate->($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # update generation -------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 387 | $self->generation($self->generation + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # update history ----------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 387 | $self->_save_history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # selection ---------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 387 | $self->_select_parents(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # crossover ---------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 387 | $self->_crossover(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # mutation ----------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 387 | $self->_mutation(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 2 | ▶ | croak('You cannot preserve more chromosomes than is in population!') if $self->preserve > $self->population; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 2 | my @preserved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 2 | ▶ | for(my $i = 0; $i != $generations; $i++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # terminate ---------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 2 | ▶ | last if $self->terminate and $self->terminate->($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->terminate and $self->terminate->($self)
MC/DC0%0/2
$self->terminate and $self->terminate->($self)
$self->terminate
$self->terminate->($self)
Truth table33%1/3
A and B
A= $self->terminateB= $self->terminate->($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # update generation -------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $self->generation($self->generation + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # update history ----------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $self->_save_history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | #--------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # preservation of N unique chromosomes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | @preserved = map { clone($_) } @{ $self->getFittest_as_arrayref($self->preserve - 1, 1) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # selection ---------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $self->_select_parents(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # crossover ---------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->_crossover(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # mutation ----------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $self->_mutation(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | #--------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | for(@preserved){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my $idx = int rand @{$self->chromosomes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | $self->chromosomes->[$idx] = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $self->_fitness->{$idx} = $self->fitness()->($self, $_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 377 | ▶ | if($self->strict){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $self->_strict( [ ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | push @{$self->_strict}, clone($_) for @{$self->chromosomes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # ALIASES ############################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | sub people { $_[0]->chromosomes() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
people: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | sub getHistory { $_[0]->_history() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getHistory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | sub mutProb { shift->mutation(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mutProb: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | sub crossProb { shift->crossover(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
crossProb: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub intType { shift->type() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intType: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | # STATS ################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | sub getFittest_as_arrayref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 3187 | ▶ | my ($self, $n, $uniq) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getFittest_as_arrayref: called CC=10 SCAR=35.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 3187 | ▶ | $n ||= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$n ||= 1
MC/DC100%1/1
$n ||= 1
$n
Truth table100%2/2
A
A= $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 3187 | ▶ | $self->_calculate_fitness_all() unless scalar %{ $self->_fitness }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 3187 | my @keys = sort { $self->_fitness->{$a} <=> $self->_fitness->{$b} } 0..$#{$self->chromosomes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 3187 | ▶ | if($uniq){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | my %grep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | my $chromosomes = $self->chromosomes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | if( my $pkg = $self->_package ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | my %tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | @keys = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | my $key = ${ tied( @{ $chromosomes->[ $_ ] } ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | #my $key = md5_hex( ${ tied( @{ $chromosomes->[ $_ ] } ) } ); # ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | $tmp{ $key } && 0 or $tmp{ $key } = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$tmp{$key} and 0
MC/DC0%0/1
$tmp{$key} and 0
$tmp{$key}
Truth table0%0/2
A
A= $tmp{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | #@keys = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # my $add_to_list = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # my $key = md5_hex(${tied(@{$chromosomes->[$_]})}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # unless($grep{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # $grep{$key} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # $add_to_list = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | # $add_to_list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # } @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | my %tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | @keys = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | my $key = md5_hex( join( q[:], @{ $chromosomes->[ $_ ] } ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | $tmp{ $key } && 0 or $tmp{ $key } = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$tmp{$key} and 0
MC/DC0%0/1
$tmp{$key} and 0
$tmp{$key}
Truth table0%0/2
A
A= $tmp{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 3187 | ▶ | $n = scalar @keys if $n > scalar @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 3187 | return [ reverse @{$self->chromosomes}[ splice @keys, $#keys - $n + 1, $n ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 3187 | ▶ | sub getFittest { return wantarray ? @{ shift->getFittest_as_arrayref(@_) } : shift @{ shift->getFittest_as_arrayref(@_) }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getFittest: called CC=2 SCAR=8.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | sub getAvgFitness { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getAvgFitness: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my @minmax = minmax values %{$self->_fitness}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | my $mean = sum(values %{$self->_fitness}) / scalar values %{$self->_fitness}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | return $minmax[1], int($mean), $minmax[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 434 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||