Algorithm-Evolutionary-Fitness
view release on metacpan or search on metacpan
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
lib/Algorithm/Evolutionary/Fitness/Knapsack.pm view on Meta::CPAN
if ( ((scalar @$profits_ref) != $n_max ) ||
((scalar @$weights_ref) != $n_max ) ) {
croak "Wrong number of profits";
}
if ( (scalar @$profits_ref) != ( scalar @$weights_ref ) ) {
croak "Profits and weights differ";
}
#Instantiate superclass
my $self = $class->SUPER::new();
$self->{'capacity'} = $capacity;
$self->{ 'rho' } = $rho;
$self->{ 'profits'} = $profits_ref;
$self->{ 'weights'} = $weights_ref;
$self->initialize();
return $self;
}
lib/Algorithm/Evolutionary/Fitness/P_Peaks.pm view on Meta::CPAN
=cut
use constant VARS => qw( bits generator regex );
sub new {
my $class = shift;
my ($peaks, $bits ) = @_;
croak "No peaks" if !$peaks;
croak "Too few bits" if !$bits;
my $self = $class->SUPER::new();
#Generate peaks
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));
}
lib/Algorithm/Evolutionary/Fitness/Rastrigin.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 ( $n_dimensions ) = @_;
#Instantiate superclass
my $self = $class->SUPER::new();
#Assign stuff
$self->{'n_dimensions'} = $n_dimensions;
$self->{'_base_fitness'} = RASTRIGIN_A*$n_dimensions;
$self->initialize();
return $self;
}
sub _really_apply {
my $self = shift;
lib/Algorithm/Evolutionary/Fitness/Royal_Road.pm view on Meta::CPAN
=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( @_ );
}
lib/Algorithm/Evolutionary/Fitness/Trap.pm view on Meta::CPAN
sub new {
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/wP_Peaks.pm view on Meta::CPAN
my @weights;
if ( ref $_[0] eq 'HASH' ) {
push @weights, 1;
for (my $i = 0; $i < $_[0]->{'number_of_peaks'}-1; $i ++ ) {
push @weights, $_[0]->{'weight'};
}
} else {
@weights = @_;
}
my $self = $class->SUPER::new();
#Generate peaks
my $generator = new String::Random;
my @peaks;
my $regex = "\[01\]{$bits}";
for my $s ( qw( bits generator regex ) ) {
eval "\$self->{'$s'} = \$$s";
}
while ( @weights ) {
my $this_w = shift @weights;
( run in 0.628 second using v1.01-cache-2.11-cpan-49f99fa48dc )