Pro/Mutation/Combination.pm

filter: Statementstmt 100% 34 / 34 Branchbran 87.5% 7 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 87.2% 48 / 55 CC 7 SCAR 15.1
CC
7
Cov
93%
run
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
« Pro/Crossover/PMX.pm ↑ Summary Pro/Crossover/OX.pm »
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
BranchTrueFalseTotal
if ($rand < $inv) { } 34 1090 1124
elsif ($rand < $mutation) { } 22 1068 1090
26 elsif($rand < $mutation){
27 22 my $el = int rand @{$chromosomes->[$idx]};
28 22 my $new = int rand @{$_translations->[0]};
29 22 ▶ next if $new == $chromosomes->[$idx]->[$el];
Branch: 1 branch
BranchTrueFalseTotal
if $new == $chromosomes->[$idx][$el] 3 19 22
30
31 19 ▶ my $id = first_index { $_ == $new } @{$chromosomes->[$idx]};
Subroutine __ANON__: called CC=1 SCAR=0.0
32 19 ▶ $chromosomes->[$idx]->[$id] = $chromosomes->[$idx]->[$el] if defined $id and $id != -1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id and $id != -1 19 0 19
Condition33%1/3
defined $id and $id != -1
!ll&&!rl&&r
0019
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
ABresult
0X0
100
111
33 19 $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;
« Pro/Crossover/PMX.pm ↑ Summary Pro/Crossover/OX.pm »