Algorithm-Evolutionary-Fitness
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Fitness.pm view on Meta::CPAN
=head2 new()
Initializes common variables, like the number of evaluations. Cache is not initialized.
=cut
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
$self->initialize();
return $self;
}
=head2 initialize()
Called from new, initializes the evaluations counter.
=cut
lib/Algorithm/Evolutionary/Fitness/Any.pm view on Meta::CPAN
=head2 new( $function )
Assigns default variables
=cut
sub new {
my $class = shift;
my $self = { _function => shift || croak "No functiona rray" };
bless $self, $class;
$self->initialize();
return $self;
}
=head2 apply( $individual )
Applies the instantiated problem to a chromosome. It is actually a
wrapper around C<_apply>.
=cut
lib/Algorithm/Evolutionary/Fitness/ECC.pm view on Meta::CPAN
Creates a new instance of the problem, with the said number of bits and peaks
=cut
sub new {
my $class = shift;
my ($number_of_codewords, $min_distance ) = @_;
croak "Too few codewords" if !$number_of_codewords;
croak "Distance too small" if !$min_distance;
my $self = $class->SUPER::new();
bless $self, $class;
$self->initialize();
$self->{'number_of_codewords'} = $number_of_codewords;
return $self;
}
=head2 _really_apply
Applies the instantiated problem to a chromosome
=cut
lib/Algorithm/Evolutionary/Fitness/P_Peaks.pm view on Meta::CPAN
my $generator = new String::Random;
my @peaks;
my $regex = "\[01\]{$bits}";
for my $s ( VARS ) {
eval "\$self->{'$s'} = \$$s";
}
for my $p ( 1..$peaks ) {
push( @peaks, $generator->randregex($regex));
}
$self->{'peaks'} = \@peaks;
bless $self, $class;
$self->initialize();
return $self;
}
=head2 random_string()
Returns random string in the same style than the peaks. Useful for testing.
=cut
lib/Algorithm/Evolutionary/Fitness/String.pm view on Meta::CPAN
=head2 new()
Initializes the cache
=cut
sub new {
my $class = shift;
my $self = { _cache => {} };
bless $self, $class;
return $self;
}
=head2 _apply( $individual )
Applies the instantiated problem to a chromosome, delegating to a specific function
=cut
sub _apply {
lib/Algorithm/Evolutionary/Fitness/Trap.pm view on Meta::CPAN
my $class = shift;
my $number_of_bits = shift || croak "Need non-null number of bits\n";
my $a = shift || $number_of_bits - 1;
my $b = shift || $number_of_bits;
my $z = shift || $number_of_bits - 1;
croak "Z too big" if $z >= $number_of_bits;
croak "Z too small" if $z < 1;
croak "A must be less than B" if $a > $b;
my $self = $class->SUPER::new();
bless $self, $class;
$self->initialize();
$self->{'l'} = $number_of_bits;
$self->{'a'} = $a;
$self->{'b'} = $b;
$self->{'z'} = $z;
return $self;
}
=head2 _really_apply
lib/Algorithm/Evolutionary/Fitness/ZDT1.pm view on Meta::CPAN
=head2 new
Creates a new instance of the problem, with the said number of bits and peaks
=cut
sub new {
my $class = shift;
my $number_of_bits = shift || croak "Need non-null number of bits\n";
my $self = { '_number_of_bits' => $number_of_bits };
bless $self, $class;
$self->initialize();
return $self;
}
=head2 _really_apply
Applies the instantiated problem to a chromosome
=cut
lib/Algorithm/Evolutionary/Fitness/wP_Peaks.pm view on Meta::CPAN
my @peaks;
my $regex = "\[01\]{$bits}";
for my $s ( qw( bits generator regex ) ) {
eval "\$self->{'$s'} = \$$s";
}
while ( @weights ) {
my $this_w = shift @weights;
push( @peaks, [$this_w, $generator->randregex($regex)]);
}
$self->{'peaks'} = \@peaks;
bless $self, $class;
$self->initialize();
return $self;
}
=head2 random_string
Returns random string in the same style than the peaks. Useful for testing
=cut
( run in 0.898 second using v1.01-cache-2.11-cpan-de7293f3b23 )