AI-Genetic
    
    
  
  
  
view release on metacpan or search on metacpan
  push @{$self->{PEOPLE}} =>
    $ind->newRandom($newArgs) for 1 .. $self->{POPSIZE};
  $_->fitness($self->{FITFUNC}) for @{$self->{PEOPLE}};
  $self->{INIT} = 1;
}
# sub people():
# returns the current list of individuals in the population.
# note: this returns the actual array ref, so any changes
# made to it (ex, shift/pop/etc) will be reflected in the
# population.
sub people {
  my $self = shift;
  if (@_) {
    $self->{PEOPLE} = shift;
    $self->{SORTED} = 0;
  }
I will not go into the details of GAs here, but here are the
bare basics. Plenty of information can be found on the web.
In a GA, a population of individuals compete for survival. Each
individual is designated by a set of genes that define its
behaviour. Individuals that perform better (as defined by the
fitness function) have a higher chance of mating with other
individuals. When two individuals mate, they swap some of
their genes, resulting in an individual that has properties
from both of its "parents". Every now and then, a mutation
occurs where some gene randomly changes value, resulting in
a different individual. If all is well defined, after a few
generations, the population should converge on a "good-enough"
solution to the problem being tackled.
A GA implementation runs for a discrete number of time steps
called I<generations>. What happens during each generation can
vary greatly depending on the strategy being used (See 
L</"STRATEGIES"> for more info).
Typically, a variation of the following happens at
each generation:
=item I<$ga>-E<gt>B<sortIndividuals>(?[I<ListOfIndividuals>]?)
Given an anonymous list of individuals, this method sorts them according
to fitness, returning an anonymous list of the sorted individuals.
=item I<$ga>-E<gt>B<people>()
Returns an anonymous list of individuals of the current population.
B<IMPORTANT>: the actual array reference used by the AI::Genetic object
is returned, so any changes to it will be reflected in I<$ga>.
=item I<$ga>-E<gt>B<size>(?I<newSize>?)
This method is used to query and set the population size.
=item I<$ga>-E<gt>B<crossProb>(?I<newProb>?)
This method is used to query and set the crossover rate.
=item I<$ga>-E<gt>B<mutProb>(?I<newProb>?)
Genetic/OpSelection.pm view on Meta::CPAN
package AI::Genetic::OpSelection;
use strict;
my @wheel;
my $wheelPop;
# sub init():
# initializes the roulette wheel array.
# must be called whenever the population changes.
# only useful for roulette().
sub initWheel {
  my $pop = shift;
  my $tot = 0;
  $tot += $_->score for @$pop;
  # if all population has zero score, then none
  # deserves to be selected.
    I will not go into the details of GAs here, but here are the bare
    basics. Plenty of information can be found on the web.
    In a GA, a population of individuals compete for survival. Each
    individual is designated by a set of genes that define its behaviour.
    Individuals that perform better (as defined by the fitness function)
    have a higher chance of mating with other individuals. When two
    individuals mate, they swap some of their genes, resulting in an
    individual that has properties from both of its "parents". Every now and
    then, a mutation occurs where some gene randomly changes value,
    resulting in a different individual. If all is well defined, after a few
    generations, the population should converge on a "good-enough" solution
    to the problem being tackled.
    A GA implementation runs for a discrete number of time steps called
    *generations*. What happens during each generation can vary greatly
    depending on the strategy being used (See the section on "STRATEGIES"
    for more info). Typically, a variation of the following happens at each
    generation:
        results are cached for speed.
    *$ga*->sortIndividuals(?[*ListOfIndividuals*]?)
        Given an anonymous list of individuals, this method sorts them
        according to fitness, returning an anonymous list of the sorted
        individuals.
    *$ga*->people()
        Returns an anonymous list of individuals of the current population.
        IMPORTANT: the actual array reference used by the AI::Genetic object
        is returned, so any changes to it will be reflected in *$ga*.
    *$ga*->size(?*newSize*?)
        This method is used to query and set the population size.
    *$ga*->crossProb(?*newProb*?)
        This method is used to query and set the crossover rate.
    *$ga*->mutProb(?*newProb*?)
        This method is used to query and set the mutation rate.
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 1 };
use AI::Genetic;
ok(1); # If we made it this far, we're ok.
#########################
# Insert your test code below, the Test module is use()ed here so read
# its man page ( perldoc Test ) for help writing this test script.
( run in 0.529 second using v1.01-cache-2.11-cpan-c333fce770f )