lib/Algorithm/Evolutionary/Fitness/MMDP.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 88.6% 39 / 44 CC 3 SCAR 5.8
CC
3
Cov
89%
mmdp
3.0
_really_apply
2.0
BEGIN
1.0
CRAP 1.8
« lib/Algorithm/Evolutionary.pm ↑ Summary lib/Algorithm/Evolutionary/Fitness/Base.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use lib qw( ../../../../lib );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Algorithm::Evolutionary::Fitness::MMDP - Massively Multimodal Deceptive Problem
9  
10 =head1 SYNOPSIS
11  
12 use Algorithm::Evolutionary::Fitness::MMDP;
13  
14 my @chromosome = "010101101010111111000000"
15  
16 my $fitness_func = Algorithm::Evolutionary::Fitness::MMDP::apply;
17 my $fitness = $fitness_func( $chromosome );
18  
19 my $fitness_object = Algorithm::Evolutionary::Fitness::MMDP->new()
20 $fitness = $fitness_object->apply( $chromosome)
21  
22 =head1 DESCRIPTION
23  
24 Massively Multimodal Deceptive Problem, tough for evolutionary algorithms.
25  
26 =head1 METHODS
27  
28 =cut
29  
30 package Algorithm::Evolutionary::Fitness::MMDP;
31  
32 2 our $VERSION = '3.0';
33  
34 2 ▶use base qw(Algorithm::Evolutionary::Fitness::String);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 our @unitation = qw( 1 0 0.360384 0.640576 0.360384 0 1);
37  
38 2 ▶use constant BLOCK_SIZE => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 0 ▶sub _really_apply {
Subroutine _really_apply: not called CC=1 SCAR=6.9
41 0 my $self = shift;
42 0 return $self->mmdp( @_ );
43 }
44  
45 =head2 mmdp( $string )
46  
47 Computes the MMDP value for a binary string, storing it in a cache.
48  
49 =cut
50  
51 6 ▶sub mmdp {
Subroutine mmdp: called CC=3 SCAR=11.0
Pod documented
52 6 my $self = shift;
53 6 my $string = shift;
54 6 my $cache = $self->{'_cache'};
55 6 ▶ if ( $cache->{$string} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{$string}) 0 6 6
56 0 return $cache->{$string};
57 }
58 6 my $fitness = 0;
59 6 ▶ for ( my $i = 0; $i < length($string); $i+= BLOCK_SIZE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $string) 6 6 12
60 6 my $block = substr( $string, $i, BLOCK_SIZE );
61 6 my $ones = grep ( /1/, split(//,$block));
62 6 $fitness += $unitation[$ones];
63 }
64 6 $cache->{$string} = $fitness;
65 6 return $fitness;
66 }
67  
68 =head1 Copyright
69
70 This file is released under the GPL. See the LICENSE file included in this distribution,
71 or go to http://www.fsf.org/licenses/gpl.txt
72  
73 =cut
74  
75 2 "What???";
« lib/Algorithm/Evolutionary.pm ↑ Summary lib/Algorithm/Evolutionary/Fitness/Base.pm »