Pro/Mutation/Listvector.pm

filter: Statementstmt 82.9% 39 / 47 Branchbran 64.2% 9 / 14 Conditioncond 46.6% 7 / 15 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 68.8% 64 / 93 CC 14 SCAR 27.4
CC
14
Cov
72%
run
20.6
BEGIN
1.0
BEGIN
1.0
CRAP 15.4
« Pro/Array/Type.pm ↑ Summary Pro/Selection/RouletteBasic.pm »
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
BranchTrueFalseTotal
if rand() >= $mutation 6668 232 6900
22  
23 232 ▶ if($ga->variable_length){
Branch: 1 branch
BranchTrueFalseTotal
if ($ga->variable_length) { } 159 73 232
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
BranchTrueFalseTotal
if ($rand < 0.4 and $range > 2) { } 66 93 159
elsif ($rand < 0.8 and $range < $_translations->$#*) { } 0 93 93
Condition66%2/3
$rand < "0.4" and $range > 2
!ll&&!rl&&r
93066
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
ABresult
0X0
100
111
29 66 ▶ if($rand < 0.2 and $ga->variable_length > 1){ $chromosomes->[$idx]->[$min] = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($rand < 0.2 and $ga->variable_length > 1) { } 3 63 66
Condition100%3/3
$rand < "0.2" and $ga->variable_length > 1
!ll&&!rl&&r
29343
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
ABresult
0X0
100
111
30 63 else{ pop @{$chromosomes->[$idx]}; }
31 ▶ }elsif($rand < 0.8 and $range < $#$_translations){
Condition66%2/3
$rand < "0.8" and $range < $_translations->$#*
!ll&&!rl&&r
31620
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->$#*
ABresult
0X0
100
111
32 0 ▶ if($rand < 0.6 and $ga->variable_length > 1 and not $chromosomes->[$idx]->[0]){
Branch: 2 branches
BranchTrueFalseTotal
if ($rand < 0.6 and $ga->variable_length > 1 and not $chromosomes->[$idx][0]) { } 0 0 0
elsif (exists $$_translations[scalar @{$chromosomes->[$idx];}]) { } 0 0 0
Condition0%0/6
$rand < "0.6" and $ga->variable_length > 1 and not $chromosomes->[$idx][0]
!ll&&!rl&&r
000
$rand < "0.6" and $ga->variable_length > 1
!ll&&!rl&&r
000
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]
ABCresult
0XX0
10X0
1100
1111
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;
« Pro/Array/Type.pm ↑ Summary Pro/Selection/RouletteBasic.pm »