use Algorithm::Evolutionary qw( Individual::BitString
Op::Mutation Op::Crossover
Op::RouletteWheel
Op::Breeder_Diverser);
use Algorithm::Evolutionary::Utils qw(average);
my @pop;
my $number_of_bits = 20;
my $population_size = 20;
my $replacement_rate = 0.5;
for ( 1..$population_size ) {
my $indi = new Algorithm::Evolutionary::Individual::BitString $number_of_bits ; #Creates random individual
$indi->evaluate( $onemax );
push( @pop, $indi );
}
my $m = new Algorithm::Evolutionary::Op::Mutation 0.5;
my $c = new Algorithm::Evolutionary::Op::Crossover; #Classical 2-point crossover
my $selector = new Algorithm::Evolutionary::Op::RouletteWheel $population_size; #One of the possible selectors
my $generation =
new Algorithm::Evolutionary::Op::Breeder_Diverser( $selector, [$m, $c] );
my @sortPop = sort { $b->Fitness() <=> $a->Fitness() } @pop;
my $bestIndi = $sortPop[0];
my $previous_average = average( \@sortPop );
$generation->apply( \@sortPop );
Algorithm::Evolutionary::Op::Base
Breeder part of the evolutionary algorithm; takes a population and returns
another created from the first. Different from
Algorithm::Evolutionary::Op::Breeder: tries to avoid crossover among the same
individuals and also re-creating an individual already in the pool. In that
sense it "diverses", tries to diversify the population. In general,
it works better in environments where high diversity is needed (like, for
instance, in Algorithm::MasterMind.
Creates a breeder, with a selector and array of operators
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.
It is valid only for string-denominated chromosomes. Checks that
the offspring is different from parents before inserting it.
More or less in the same ballpark, alternatives to this one
- Algorithm::Evolutionary::Op::GeneralGeneration
- Algorithm::Evolutionary::Op::Breeder
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: 2013/01/07 13:54:20 $
$Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Op/Breeder_Diverser.pm,v 1.7 2013/01/07 13:54:20 jmerelo Exp $
$Author: jmerelo $
$Revision: 1.7 $