``````use strict;
use warnings;

use lib qw( ../../../../lib );

Algorithm::Evolutionary::Fitness::MMDP - Massively Multimodal Deceptive Problem

use Algorithm::Evolutionary::Fitness::MMDP;

my @chromosome = "010101101010111111000000"

my \$fitness_func = Algorithm::Evolutionary::Fitness::MMDP::apply;
my \$fitness = \$fitness_func( \$chromosome );

my \$fitness_object = Algorithm::Evolutionary::Fitness::MMDP->new()
\$fitness = \$fitness_object->apply( \$chromosome)

Massively Multimodal Deceptive Problem, tough for evolutionary algorithms.

=cut

package Algorithm::Evolutionary::Fitness::MMDP;

our \$VERSION = '3.0';

use base qw(Algorithm::Evolutionary::Fitness::String);

our @unitation = qw( 1 0 0.360384 0.640576 0.360384 0 1);

use constant BLOCK_SIZE => 6;

sub _really_apply {
my \$self = shift;
return \$self->mmdp( @_ );
}

Computes the MMDP value for a binary string, storing it in a cache.

=cut

sub mmdp {
my \$self = shift;
my \$string = shift;
my \$cache = \$self->{'_cache'};
if ( \$cache->{\$string} ) {
return \$cache->{\$string};
}
my \$fitness = 0;
for ( my \$i = 0; \$i < length(\$string); \$i+= BLOCK_SIZE ) {
my \$block = substr( \$string, \$i, BLOCK_SIZE );
my \$ones = grep ( /1/, split(//,\$block));
\$fitness += \$unitation[\$ones];
}
\$cache->{\$string} = \$fitness;
return \$fitness;
}