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 2     2   8417 use strict;
  2         4  
  2         75  
2 2     2   10 use warnings;
  2         4  
  2         71  
3              
4 2     2   11 use lib qw( ../../../../lib );
  2         3  
  2         18  
5              
6             =head1 NAME
7              
8             Algorithm::Evolutionary::Fitness::MMDP - Massively Multimodal Deceptive Problem
9              
10             =head1 SYNOPSIS
11              
12             my $fitness = Algorithm::Evolutionary::Fitness::MMDP::apply;
13              
14             =head1 DESCRIPTION
15              
16             Massively Multimodal Deceptive Problem, tough for evolutionary algorithms.
17              
18             =head1 METHODS
19              
20             =cut
21              
22             package Algorithm::Evolutionary::Fitness::MMDP;
23              
24             our ($VERSION) = ( '$Revision: 3.0 $ ' =~ / (\d+\.\d+)/ ) ;
25              
26 2     2   539 use base qw(Algorithm::Evolutionary::Fitness::String);
  2         4  
  2         1347  
27              
28             our @unitation = qw( 1 0 0.360384 0.640576 0.360384 0 1);
29              
30 2     2   315 use constant BLOCK_SIZE => 6;
  2         4  
  2         600  
31              
32             sub _really_apply {
33 0     0   0 my $self = shift;
34 0         0 return $self->mmdp( @_ );
35             }
36              
37             =head2 mmdp( $string )
38              
39             Computes the MMDP value for a binary string, storing it in a cache
40              
41             =cut
42              
43             sub mmdp {
44 6     6 1 527 my $self = shift;
45 6         9 my $string = shift;
46 6         16 my $cache = $self->{'_cache'};
47 6 50       17 if ( $cache->{$string} ) {
48 0         0 return $cache->{$string};
49             }
50 6         7 my $fitness = 0;
51 6         29 for ( my $i = 0; $i < length($string); $i+= BLOCK_SIZE ) {
52 6         9 my $block = substr( $string, $i, BLOCK_SIZE );
53 6         43 my $ones = grep ( /1/, split(//,$block));
54 6         33 $fitness += $unitation[$ones];
55             }
56 6         13 $cache->{$string} = $fitness;
57 6         34 return $fitness;
58             }
59              
60             =head1 Copyright
61            
62             This file is released under the GPL. See the LICENSE file included in this distribution,
63             or go to http://www.fsf.org/licenses/gpl.txt
64              
65             CVS Info: $Date: 2009/07/24 08:46:59 $
66             $Header: /cvsroot/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Fitness/MMDP.pm,v 3.0 2009/07/24 08:46:59 jmerelo Exp $
67             $Author: jmerelo $
68             $Revision: 3.0 $
69             $Name $
70              
71             =cut
72              
73             "What???";