Pro/Mutation/Rangevector.pm

filter: Statementstmt 70.0% 49 / 70 Branchbran 54.5% 12 / 22 Conditioncond 47.6% 10 / 21 MC/DCmcdc 38.4% 5 / 13 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 3 totaltotal 60.5% 83 / 137 CC 21 SCAR 33.3
CC
21
Cov
63%
run0
72.0
run
14.5
BEGIN
1.0
CRAP 28.0
« Pro.pm ↑ Summary Pro/Crossover/PointsAdvanced.pm »
1 package AI::Genetic::Pro::Mutation::Rangevector;
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 3 ▶use Math::Random qw(random_uniform_integer);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Data::Dumper; $Data::Dumper::Sortkeys = 1;
8 #=======================================================================
9 3 ▶sub new { bless \$_[0], $_[0]; }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 #=======================================================================
11 sub run {
12 5 ▶ my ($self, $ga) = @_;
Subroutine run: called CC=14 SCAR=26.7
Pod undocumented
13  
14 # this is declared here just for speed
15 5 my $mutation = $ga->mutation;
16 5 my $chromosomes = $ga->chromosomes;
17 5 my $_translations = $ga->_translations;
18 5 my ($fitness, $_fitness) = ($ga->fitness, $ga->_fitness);
19  
20 # main loop
21 5 for my $idx (0..$#$chromosomes){
22 6900 ▶ next if rand() >= $mutation;
Branch: 1 branch
BranchTrueFalseTotal
if rand() >= $mutation 6544 356 6900
23  
24 356 ▶ if($ga->variable_length){
Branch: 1 branch
BranchTrueFalseTotal
if ($ga->variable_length) { } 290 66 356
25 290 my $rand = rand();
26  
27 290 ▶ my $min = first_index { $_ } @{$chromosomes->[$idx]};
Subroutine __ANON__: called CC=1 SCAR=0.0
28 290 my $range = $#{$chromosomes->[$idx]} - $min + 1;
29
30 290 ▶ if($rand < 0.4 and $range > 2){
Branch: 2 branches
BranchTrueFalseTotal
if ($rand < 0.4 and $range > 2) { } 126 164 290
elsif ($rand < 0.8 and $range < scalar @{$_translations;}) { } 1 163 164
Condition66%2/3
$rand < "0.4" and $range > 2
!ll&&!rl&&r
1640126
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
31 126 ▶ 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) { } 30 96 126
Condition100%3/3
$rand < "0.2" and $ga->variable_length > 1
!ll&&!rl&&r
583830
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
32 96 else{ pop @{$chromosomes->[$idx]}; }
33 109 ▶ }elsif($rand < 0.8 and $range < scalar @{$_translations}){
Condition100%3/3
$rand < "0.8" and $range < scalar @{$_translations;}
!ll&&!rl&&r
551081
MC/DC100%2/2
$rand < "0.8" and $range < scalar @{$_translations;}
$rand < "0.8" $range < scalar @{$_translations;}
Truth table100%3/3
A and B
A= $rand < "0.8"B= $range < scalar @{$_translations;}
ABresult
0X0
100
111
34 1 ▶ 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 1 1
elsif (exists $$_translations[scalar @{$chromosomes->[$idx];}]) { } 1 0 1
Condition33%2/6
$rand < "0.6" and $ga->variable_length > 1 and not $chromosomes->[$idx][0]
!ll&&!rl&&r
100
$rand < "0.6" and $ga->variable_length > 1
!ll&&!rl&&r
100
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 table25%1/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
35 0 $chromosomes->[$idx]->[ $min - 1 ] = random_uniform_integer(1, @{$_translations->[ $min - 1 ]}[1..2]);
36 1 }elsif(exists $_translations->[scalar @{$chromosomes->[$idx]}]){
37 1 push @{$chromosomes->[$idx]}, random_uniform_integer(1, @{$_translations->[scalar @{$chromosomes->[$idx]}]}[1..2]);
38 }
39 }else{
40 163 my $id = $min + int rand($range - 1);
41 163 $chromosomes->[$idx]->[$id] = random_uniform_integer(1, @{$_translations->[$id]}[1..2]);
42 }
43 }else{
44 66 my $id = int rand @{$chromosomes->[$idx]};
45 66 $chromosomes->[$idx]->[$id] = random_uniform_integer(1, @{$_translations->[$id]}[1..2]);
46 }
47
48 # we need to change fitness
49 356 $_fitness->{$idx} = $fitness->($ga, $chromosomes->[$idx]);
50 }
51
52 5 return 1;
53 }
54 #=======================================================================
55 sub run0 {
56 0 ▶ my ($self, $ga) = @_;
Subroutine run0: not called CC=8 SCAR=42.8
Pod undocumented
57  
58 # this is declared here just for speed
59 0 my $mutation = $ga->mutation;
60
61 # main loop
62 0 foreach my $chromosome (@{$ga->{chromosomes}}){
63 0 ▶ next if rand() <= $mutation;
Branch: 1 branch
BranchTrueFalseTotal
if rand() <= $mutation 0 0 0
64
65 0 ▶ if($ga->variable_length){
Branch: 1 branch
BranchTrueFalseTotal
if ($ga->variable_length) { } 0 0 0
66 0 my $rand = rand();
67 0 ▶ if($rand < 0.33 and $#$chromosome > 1){
Branch: 2 branches
BranchTrueFalseTotal
if ($rand < 0.33 and $chromosome->$#* > 1) { } 0 0 0
elsif ($rand < 0.66 and $chromosome->$#* < $#{$ga->_translations;}) { } 0 0 0
Condition0%0/3
$rand < "0.33" and $chromosome->$#* > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$rand < "0.33" and $chromosome->$#* > 1
$rand < "0.33" $chromosome->$#* > 1
Truth table0%0/3
A and B
A= $rand < "0.33"B= $chromosome->$#* > 1
ABresult
0X0
100
111
68 0 pop @$chromosome;
69 0 ▶ }elsif($rand < 0.66 and $#$chromosome < $#{$ga->_translations}){
Condition0%0/3
$rand < "0.66" and $chromosome->$#* < $#{$ga->_translations;}
!ll&&!rl&&r
000
MC/DC0%0/2
$rand < "0.66" and $chromosome->$#* < $#{$ga->_translations;}
$rand < "0.66" $chromosome->$#* < $#{$ga->_translations;}
Truth table0%0/3
A and B
A= $rand < "0.66"B= $chromosome->$#* < $#{$ga->_translations;}
ABresult
0X0
100
111
70 0 push @$chromosome, random_uniform_integer(1, @{$ga->_translations->[scalar @$chromosome]});
71 }else{
72 0 my $idx = int rand @$chromosome;
73 0 $chromosome->[$idx] = random_uniform_integer(1, @{$ga->_translations->[$idx]});
74 }
75 }else{
76 0 my $idx = int rand @$chromosome;
77 0 $chromosome->[$idx] = random_uniform_integer(1, @{$ga->_translations->[$idx]});
78 }
79 }
80
81 0 return 1;
82 }
83 #=======================================================================
84 3 1;
« Pro.pm ↑ Summary Pro/Crossover/PointsAdvanced.pm »