Algorithm-Evolutionary-Simple
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Simple.pm view on Meta::CPAN
return map( $_*$slots, @$wheel );
}
sub produce_offspring {
my $pool = shift || croak "Pool missing";
my $offspring_size = shift || croak "Population size needed";
my @population = ();
my $population_size = scalar( @$pool );
for ( my $i = 0; $i < $offspring_size/2; $i++ ) {
my $first = $pool->[rand($population_size)];
my $second = $pool->[rand($population_size)];
push @population, crossover( $first, $second );
}
map( $_ = mutate($_), @population );
return @population;
}
sub mutate {
my $chromosome = shift;
my $mutation_point = int(rand( length( $chromosome )));
substr($chromosome, $mutation_point, 1,
( substr($chromosome, $mutation_point, 1) eq 1 )?0:1 );
( run in 1.296 second using v1.01-cache-2.11-cpan-39bf76dae61 )