Algorithm-Evolve
view release on metacpan or search on metacpan
Revision history for Perl extension Algorithm::Evolve.
0.03
- Update selection/replacement dispatch method to play well with DProf,
may change back someday..
- Speedup of A::E::Util::str_agreement at the price of utf8
- Other misc speedups
- Change StringEvolver to use blessed hash, for better reuse prospects
- Added ArrayEvolver, mimicking StringEvolver for array genes
- Added "Breeding Perls" example
0.02 Mon May 19 2003
- Added gladitorial selection/replacement
- Added co-evolving rock-paper-scissors example
- Lots of POD updates, added POD to StringEvolver.pm
- Added array utils to Algorithm::Evolve::Util
- Some switches can be changed dynamically (selection, replacement,
parents & children per generation)
examples/ArrayEvolver.pm view on Meta::CPAN
mutation_rate => 0.05,
crossover_pts => 2,
@_
);
}
sub new {
my $pkg = shift;
my $array = shift
|| arr_random($configs{gene_length}, $configs{alphabet});
return bless { _gene => $array }, $pkg;
}
sub crossover {
my ($pkg, $c1, $c2) = @_;
return map { $pkg->new($_) }
arr_crossover($c1->gene, $c2->gene, $configs{crossover_pts});
}
sub fitness {
my $self = shift;
examples/StringEvolver.pm view on Meta::CPAN
mutation_rate => 0.05,
crossover_pts => 2,
@_
);
}
sub new {
my $pkg = shift;
my $string = shift
|| str_random($configs{gene_length}, $configs{alphabet});
return bless { _gene => $string }, $pkg;
}
sub crossover {
my ($pkg, $s1, $s2) = @_;
return map { $pkg->new($_) }
str_crossover($s1->gene, $s2->gene, $configs{crossover_pts});
}
sub fitness {
my $self = shift;
lib/Algorithm/Evolve.pm view on Meta::CPAN
###########################
sub debug {
print @_, "\n" if $DEBUG;
}
sub new {
my $pkg = shift;
my $p = bless {
generations => 0,
parents_per_gen => 2,
@_
}, $pkg;
$p->{random_seed} ||= int(rand $rand_max);
srand( $p->random_seed );
$p->{selection} ||= $p->{replacement};
$p->{replacement} ||= $p->{selection};
lib/Algorithm/Evolve.pm view on Meta::CPAN
Algorithm::Evolve maintains a population of critter objects to be evolved. You
may evolve any type of objects you want, provided the class supplies the
following methods:
=over
=item C<Class-E<gt>new()>
This method will be called as a class method with no arguments. It must return
a blessed critter object. It is recommended that the returned critter's genes
be randomly initialized.
=item C<Class-E<gt>crossover( $critter1, $critter2 )>
This method will also be called as a class method, with two critter objects as
arguments. It should return a list of two new critter objects based on the
genes of the passed objects.
=item C<$critter-E<gt>mutate()>
( run in 0.641 second using v1.01-cache-2.11-cpan-de7293f3b23 )