| 1 | package AI::Genetic::Pro::Mutation::Listvector; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use List::MoreUtils qw(first_index); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #use Data::Dumper; $Data::Dumper::Sortkeys = 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | sub new { bless \$_[0], $_[0]; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | my ($self, $ga) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=14 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # this is declared here just for speed | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | my $mutation = $ga->mutation; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | my $chromosomes = $ga->chromosomes; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | my $_translations = $ga->_translations; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | my ($fitness, $_fitness) = ($ga->fitness, $ga->_fitness); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # main loop | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | for my $idx (0..$#$chromosomes){ | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6900 | ▶ | next if rand() >= $mutation; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 232 | ▶ | if($ga->variable_length){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 159 | my $rand = rand(); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 159 | ▶ | my $min = first_index { $_ } @{$chromosomes->[$idx]}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 159 | my $range = $#{$chromosomes->[$idx]} - $min + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 159 | ▶ | if($rand < 0.4 and $range > 2){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$rand < "0.4" and $range > 2
MC/DC50%1/2
$rand < "0.4" and $range > 2
$rand < "0.4"
$range > 2
Truth table66%2/3
A and B
A= $rand < "0.4"B= $range > 2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 66 | ▶ | if($rand < 0.2 and $ga->variable_length > 1){ $chromosomes->[$idx]->[$min] = 0; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$rand < "0.2" and $ga->variable_length > 1
MC/DC100%2/2
$rand < "0.2" and $ga->variable_length > 1
$rand < "0.2"
$ga->variable_length > 1
Truth table100%3/3
A and B
A= $rand < "0.2"B= $ga->variable_length > 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 63 | else{ pop @{$chromosomes->[$idx]}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | ▶ | }elsif($rand < 0.8 and $range < $#$_translations){ | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rand < "0.8" and $range < $_translations->$#*
MC/DC0%0/2
$rand < "0.8" and $range < $_translations->$#*
$rand < "0.8"
$range < $_translations->$#*
Truth table66%2/3
A and B
A= $rand < "0.8"B= $range < $_translations->$#*
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if($rand < 0.6 and $ga->variable_length > 1 and not $chromosomes->[$idx]->[0]){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$rand < "0.6" and $ga->variable_length > 1 and not $chromosomes->[$idx][0]
$rand < "0.6" and $ga->variable_length > 1
MC/DC0%0/3
$rand < "0.6" and $ga->variable_length > 1 and not $chromosomes->[$idx][0]
$rand < "0.6"
$ga->variable_length > 1
not $chromosomes->[$idx][0]
Truth table0%0/4
A and B and not(C)
A= $rand < "0.6"B= $ga->variable_length > 1C= not $chromosomes->[$idx][0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $chromosomes->[$idx]->[ $min - 1 ] = 1 + int rand $#{$_translations->[ $min - 1 ]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | }elsif(exists $_translations->[scalar @{$chromosomes->[$idx]}]){ | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | push @{$chromosomes->[$idx]}, 1 + int rand $#{$_translations->[scalar @{$chromosomes->[$idx]}]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 93 | my $id = $min + int rand($range - 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 93 | $chromosomes->[$idx]->[$id] = 1 + int rand $#{$_translations->[$id]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 73 | my $id = int rand @{$chromosomes->[$idx]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 73 | $chromosomes->[$idx]->[$id] = 1 + int rand $#{$_translations->[$id]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # we need to change fitness | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 232 | $_fitness->{$idx} = $fitness->($ga, $chromosomes->[$idx]); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||