Algorithm-Evolutionary-Fitness
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Fitness/Royal_Road.pm view on Meta::CPAN
use strict;
use warnings;
use lib qw( ../../../../lib );
=head1 NAME
Algorithm::Evolutionary::Fitness::Royal_Road - Mitchell's Royal Road function
=head1 SYNOPSIS
my $block_size = 4;
my $rr = Algorithm::Evolutionary::Fitness::Royal_Road->new( $block_size );
=head1 DESCRIPTION
Royal Road function, adds block_size to fitness only when the block is complete
=head1 METHODS
=cut
package Algorithm::Evolutionary::Fitness::Royal_Road;
our ($VERSION) = ( '$Revision: 3.1 $ ' =~ / (\d+\.\d+)/ ) ;
use base qw(Algorithm::Evolutionary::Fitness::String);
=head2 new( $block_size )
Creates a new instance of the problem, with the said block size.
=cut
sub new {
my $class = shift;
my ( $block_size ) = @_;
my $self = $class->SUPER::new();
$self->{'_block_size'} = $block_size;
$self->initialize();
return $self;
}
sub _really_apply {
my $self = shift;
return $self->royal_road( @_ );
}
=head2 royal_road( $string )
Computes the royal road function with given block size. Results are
cached by default.
=cut
sub royal_road {
my $self = shift;
my $string = shift;
my $cache = $self->{'_cache'};
if ( $cache->{$string} ) {
return $cache->{$string};
}
( run in 0.700 second using v1.01-cache-2.11-cpan-39bf76dae61 )