Algorithm-Evolve
view release on metacpan or search on metacpan
examples/breeding_perls.pl view on Meta::CPAN
123456789101112#!/usr/bin/perl
## This example is geared towards those who are familiar with a certain
## infamous PerlMonks writeup...
##############################################################################
## Genetic Programming or breeding Perls (http://perlmonks.org/?node_id=31147)
## is one of the all-time most popular nodes on PerlMonks. It's a great
## example of genetic programming, the catch being that it uses eval to breed
## real Perl programs. The goal is to find a Perl expression that evaluates to
## a target number. This is a reimplementation of that writeup's code using
examples/rock_paper_scissors.pl view on Meta::CPAN
1234567891011121314151617181920#!/usr/bin/perl
use
strict;
use
warnings;
## this example script has POD -- check it out!
our
@ISA
= (
'StringEvolver'
);
use
Algorithm::Evolve;
sub
compare {
my
(
$class
,
$crit1
,
$crit2
) =
@_
;
my
(
$string1
,
$string2
) = (
$crit1
->gene,
$crit2
->gene);
my
(
$score1
,
$score2
) = (0, 0);
my
$length
=
length
(
$string1
);
my
$offset1
=
int
rand
$length
;
my
$offset2
=
int
rand
$length
;
examples/string_evolver.pl view on Meta::CPAN
12345678910111213141516#!/usr/bin/perl
## A trivial string evolver simulation using StringEvolver.pm. It evolves
## strings of all 1's, the "Hello World" of evoluationary algorithms. ;)
use
Algorithm::Evolve;
use
StringEvolver;
sub
callback {
my
$pop
=
shift
;
## Print out statistics every 50 generations
unless
(
$pop
->generations % 50) {
printf
"generations:%d best_fit:%d avg_fitness:%f\n"
,
$pop
->generations,
$pop
->best_fit->fitness,
$pop
->avg_fitness;
( run in 0.238 second using v1.01-cache-2.11-cpan-1dc43b0fbd2 )