| 1 | package AI::Genetic::Pro::Mutation::Combination; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use List::MoreUtils qw(first_index); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | #use Data::Dumper; $Data::Dumper::Sortkeys = 1; | ||||||||||||||||||||||||||||
| 7 | #======================================================================= | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | sub new { bless \$_[0], $_[0]; } | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | #======================================================================= | ||||||||||||||||||||||||||||
| 10 | sub run { | ||||||||||||||||||||||||||||
| 11 | 1 | ▶ | my ($self, $ga) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # this is declared here just for speed | ||||||||||||||||||||||||||||
| 14 | 1 | my $mutation = $ga->mutation; | |||||||||||||||||||||||||||
| 15 | 1 | my $chromosomes = $ga->chromosomes; | |||||||||||||||||||||||||||
| 16 | 1 | my $_translations = $ga->_translations; | |||||||||||||||||||||||||||
| 17 | 1 | my ($fitness, $_fitness) = ($ga->fitness, $ga->_fitness); | |||||||||||||||||||||||||||
| 18 | 1 | my $inv = $mutation / 2; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # main loop | ||||||||||||||||||||||||||||
| 21 | 1 | for my $idx (0..$#$chromosomes){ | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1124 | my $rand = rand; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1124 | ▶ | if($rand < $inv) { tied(@{$chromosomes->[$idx]})->reverse; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 26 | elsif($rand < $mutation){ | ||||||||||||||||||||||||||||
| 27 | 24 | my $el = int rand @{$chromosomes->[$idx]}; | |||||||||||||||||||||||||||
| 28 | 24 | my $new = int rand @{$_translations->[0]}; | |||||||||||||||||||||||||||
| 29 | 24 | ▶ | next if $new == $chromosomes->[$idx]->[$el]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 21 | ▶ | my $id = first_index { $_ == $new } @{$chromosomes->[$idx]}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 21 | ▶ | $chromosomes->[$idx]->[$id] = $chromosomes->[$idx]->[$el] if defined $id and $id != -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $id and $id != -1
MC/DC0%0/2
defined $id and $id != -1
defined $id
$id != -1
Truth table33%1/3
A and B
A= defined $idB= $id != -1
| |||||||||||||||||||||||||||||
| 33 | 21 | $chromosomes->[$idx]->[$el] = $new; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # we need to change fitness | ||||||||||||||||||||||||||||
| 37 | 1121 | $_fitness->{$idx} = $fitness->($ga, $chromosomes->[$idx]); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | return 1; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | #======================================================================= | ||||||||||||||||||||||||||||
| 43 | 1 | 1; | |||||||||||||||||||||||||||