File Coverage

lib/Algorithm/Evolutionary/Fitness/MMDP.pm
Criterion Covered Total %
statement 26 29 89.6
branch 1 2 50.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 34 39 87.1


line stmt bran cond sub pod time code
1 1     1   553 use strict;
  1         1  
  1         27  
2 1     1   3 use warnings;
  1         2  
  1         32  
3              
4 1     1   3 use lib qw( ../../../../lib );
  1         1  
  1         8  
5              
6             =head1 NAME
7              
8             Algorithm::Evolutionary::Fitness::MMDP - Massively Multimodal Deceptive Problem
9              
10             =head1 SYNOPSIS
11              
12             my $fitness_func = Algorithm::Evolutionary::Fitness::MMDP::apply;
13            
14             my $fitness = $fitness_func( $chromosome );
15              
16             =head1 DESCRIPTION
17              
18             Massively Multimodal Deceptive Problem, tough for evolutionary algorithms.
19              
20             =head1 METHODS
21              
22             =cut
23              
24             package Algorithm::Evolutionary::Fitness::MMDP;
25              
26             our $VERSION = '3.0';
27              
28 1     1   126 use base qw(Algorithm::Evolutionary::Fitness::String);
  1         1  
  1         303  
29              
30             our @unitation = qw( 1 0 0.360384 0.640576 0.360384 0 1);
31              
32 1     1   5 use constant BLOCK_SIZE => 6;
  1         1  
  1         189  
33              
34             sub _really_apply {
35 0     0   0 my $self = shift;
36 0         0 return $self->mmdp( @_ );
37             }
38              
39             =head2 mmdp( $string )
40              
41             Computes the MMDP value for a binary string, storing it in a cache.
42              
43             =cut
44              
45             sub mmdp {
46 6     6 1 16 my $self = shift;
47 6         12 my $string = shift;
48 6         30 my $cache = $self->{'_cache'};
49 6 50       13 if ( $cache->{$string} ) {
50 0         0 return $cache->{$string};
51             }
52 6         6 my $fitness = 0;
53 6         11 for ( my $i = 0; $i < length($string); $i+= BLOCK_SIZE ) {
54 6         8 my $block = substr( $string, $i, BLOCK_SIZE );
55 6         32 my $ones = grep ( /1/, split(//,$block));
56 6         23 $fitness += $unitation[$ones];
57             }
58 6         11 $cache->{$string} = $fitness;
59 6         31 return $fitness;
60             }
61              
62             =head1 Copyright
63            
64             This file is released under the GPL. See the LICENSE file included in this distribution,
65             or go to http://www.fsf.org/licenses/gpl.txt
66              
67             =cut
68              
69             "What???";