NAME
Algorithm::Evolutionary::Op::Generation_Skeleton - Even more customizable single generation for an evolutionary algorithm.
SYNOPSIS
#Taken from the t/general.t file, verbatim
my $m = new Algorithm::Evolutionary::Op::Bitflip; #Changes a single bit
my $c = new Algorithm::Evolutionary::Op::Crossover; #Classical 2-point crossover
use Algorithm::Evolutionary::Op::RouletteWheel;
my $popSize = 20;
my $selector = new Algorithm::Evolutionary::Op::RouletteWheel $popSize; #One of the possible selectors
use Algorithm::Evolutionary::Op::GeneralGeneration;
my $onemax = sub {
my $indi = shift;
my $total = 0;
for ( my $i = 0; $i < $indi->length(); $i ++ ) {
$total += substr( $indi->{_str}, $i, 1 );
}
return $total;
};
my @pop;
my $numBits = 10;
for ( 0..$popSize ) {
my $indi = new Algorithm::Evolutionary::Individual::BitString $numBits ; #Creates random individual
my $fitness = $onemax->( $indi );
$indi->Fitness( $fitness );
push( @pop, $indi );
}
my $generation =
new Algorithm::Evolutionary::Op::GeneralGeneration( $onemax, $selector, [$m, $c] );
my @sortPop = sort { $a->Fitness() <=> $b->Fitness() } @pop;
my $bestIndi = $sortPop[0];
$generation->apply( \@sortPop );
Base Class
Algorithm::Evolutionary::Op::Base
DESCRIPTION
Skeleton class for a general single-generation (or single step) in an evolutionary algorithm; its instantiation requires a fitness function, a Selector, a reference to an array of operators and a replacement operator
METHODS
new( $evaluation_function, $selector, $ref_to_operator_array, $replacement_operator )
Creates an algorithm, with no defaults except for the default replacement operator (defaults to Algorithm::Evolutionary::Op::ReplaceWorst)
set( $ref_to_params_hash, $ref_to_code_hash, $ref_to_operators_hash )
Sets the instance variables. Takes a ref-to-hash as input. Not intended to be used from outside the class
apply( $population )
Applies the algorithm to the population, which should have been evaluated first; checks that it receives a ref-to-array as input, croaks if it does not. Returns a sorted, culled, evaluated population for next generation.
Copyright
This file is released under the GPL. See the LICENSE file included in this distribution,
or go to http://www.fsf.org/licenses/gpl.txt
CVS Info: $Date: 2009/03/20 11:31:51 $
$Header: /cvsroot/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Op/Generation_Skeleton.pm,v 2.2 2009/03/20 11:31:51 jmerelo Exp $
$Author: jmerelo $
$Revision: 2.2 $
$Name $