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;
lib/Algorithm/Evolutionary/Individual/BitString.pm view on Meta::CPAN
Sets values of an individual; takes a hash as input. Keys are prepended an
underscore and turn into instance variables
=cut
sub set {
my $self = shift;
my $hash = shift || croak "No params here";
$self->{_chars} = [ '0', '1' ];
$self->SUPER::set( $hash );
}
=head2 decode( $gene_size, $min, $range )
Decodes to a vector, each one of whose components ranges between $min
and $max. Returns that vector
=cut
sub decode {
lib/Algorithm/Evolutionary/Individual/Tree.pm view on Meta::CPAN
=head2 asXML
Prints it as XML. It prints the tree as String, which does not mean
you will be able to get it back from this form. It's done just for
compatibity, reading from this format will be available. In the future.
=cut
sub asXML {
my $self = shift;
my $str = $self->SUPER::asXML();
# my $str2 = ">\n<atom><![CDATA[".$self->asString()."]]></atom> ";
my $str2 = ">\n<atom><![CDATA[dummy root node]]></atom> ";
$str =~ s/\/>/$str2/e ;
return $str.$str2."\n</indi>";
}
=head2 addAtom
Dummy sub
lib/Algorithm/Evolutionary/Individual/Vector.pm view on Meta::CPAN
}
=head2 asXML()
Prints it as XML. See the L<Algorithm::Evolutionary::XML|lgorithm::Evolutionary::XML> OPEAL manual for details.
=cut
sub asXML {
my $self = shift;
my $str = $self->SUPER::asXML();
my $str2 = ">" .join( "", map( "<atom>$_</atom> ", @{$self->{_array}} ));
$str =~ s/\/>/$str2/e ;
return $str."\n</indi>";
}
=head2 Chrom( [$ref_to_array]
Sets or gets the array that holds the chromosome. Not very nice, and
I would never ever do this in C++
lib/Algorithm/Evolutionary/Op/FullAlgorithm.pm view on Meta::CPAN
the algorithm: parameters, fitness functions and operators
=cut
sub set {
my $self = shift;
my $hashref = shift || croak "No params here";
my $codehash = shift;
my $opshash = shift;
$self->SUPER::set( $hashref ); # Base class only aware of options
#Now reconstruct operators
for my $o ( keys %$opshash ) { #ops are keyed by type
$self->{$opshash->{$o}->[1]->{'-id'}} =
Algorithm::Evolutionary::Op::Base::fromXML( $o, $opshash->{$o}->[1], $opshash->{$o}->[0] );
}
}
=head2 apply( $reference_to_population_array )