Algorithm-Evolve

 view release on metacpan or  search on metacpan

examples/breeding_perls.pl  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl
use lib '../lib';
 
## 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use strict;
 
## this example script has POD -- check it out!
 
use StringEvolver alphabet => [qw/R P S/], mutation_rate => 0.05;
our @ISA = ('StringEvolver');
 
use lib '../lib';
 
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/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 lib '../lib';
 
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 )