| 1 | package AI::Genetic::Pro::Crossover::Points; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 400 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 400 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 400 | ▶ | use List::MoreUtils qw(first_index); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | #use Data::Dumper; $Data::Dumper::Sortkeys = 1; | ||||||||||||||||||||||||||||
| 7 | #======================================================================= | ||||||||||||||||||||||||||||
| 8 | 400 | ▶ | sub new { bless { points => $_[1] ? $_[1] : 1 }, $_[0]; } | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 9 | #======================================================================= | ||||||||||||||||||||||||||||
| 10 | sub run { | ||||||||||||||||||||||||||||
| 11 | 414 | ▶ | my ($self, $ga) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 414 | my ($chromosomes, $parents, $crossover) = ($ga->chromosomes, $ga->_parents, $ga->crossover); | |||||||||||||||||||||||||||
| 14 | 414 | my ($fitness, $_fitness) = ($ga->fitness, $ga->_fitness); | |||||||||||||||||||||||||||
| 15 | 414 | my @children; | |||||||||||||||||||||||||||
| 16 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 17 | 414 | ▶ | while(my $elders = shift @$parents){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 18368 | my @elders = unpack 'I*', $elders; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 18368 | ▶ | unless(scalar @elders){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 0 | $_fitness->{scalar(@children)} = $fitness->($ga, $chromosomes->[$elders[0]]); | |||||||||||||||||||||||||||
| 22 | 0 | push @children, $chromosomes->[$elders[0]]; | |||||||||||||||||||||||||||
| 23 | 0 | next; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 18368 | my ($min, $max) = (0, $#{$chromosomes->[0]}); | |||||||||||||||||||||||||||
| 27 | 18368 | ▶ | if($ga->variable_length){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 11600 | for my $el(@elders){ | |||||||||||||||||||||||||||
| 29 | 22009 | ▶ | my $idx = first_index { $_ } @{$chromosomes->[$el]}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 22009 | ▶ | $min = $idx if $idx > $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 22009 | ▶ | $max = $#{$chromosomes->[$el]} if $#{$chromosomes->[$el]} < $max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 18368 | my @points; | |||||||||||||||||||||||||||
| 36 | 18368 | ▶ | if($min < $max and $max - $min > 2){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$min < $max and $max - $min > 2
MC/DC100%2/2
$min < $max and $max - $min > 2
$min < $max
$max - $min > 2
Truth table100%3/3
A and B
A= $min < $maxB= $max - $min > 2
| |||||||||||||||||||||||||||||
| 37 | 14193 | my $range = $max - $min; | |||||||||||||||||||||||||||
| 38 | 14193 | @points = map { $min + int(rand $range) } 1..$self->{points}; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 18368 | @elders = map { $chromosomes->[$_]->clone } @elders; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 18368 | for my $pt(@points){ | |||||||||||||||||||||||||||
| 44 | @elders = sort { | ||||||||||||||||||||||||||||
| 45 | 28386 | splice @$b, 0, $pt, splice( @$a, 0, $pt, @$b[0..$pt-1] ); | |||||||||||||||||||||||||||
| 46 | 0; | ||||||||||||||||||||||||||||
| 47 | } @elders; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 18368 | my %elders = map { $_ => $fitness->($ga, $elders[$_]) } 0..$#elders; | |||||||||||||||||||||||||||
| 51 | 18368 | my $maximum = (sort { $elders{$a} <=> $elders{$b} } keys %elders)[-1]; | |||||||||||||||||||||||||||
| 52 | 18368 | $_fitness->{scalar(@children)} = $elders{$maximum}; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 18368 | push @children, $elders[$maximum]; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | #------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 57 | 414 | return \@children; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | #======================================================================= | ||||||||||||||||||||||||||||
| 60 | 400 | 1; | |||||||||||||||||||||||||||