AI-Genetic
view release on metacpan or search on metacpan
-population
This defines the size of the population, i.e. how many
individuals to simultaneously exist at each generation.
Defaults to 100.
-crossover
This defines the crossover rate. Defaults to 0.95.
-mutation
This defines the mutation rate. Defaults to 0.05.
*-fitness*
This defines a fitness function. It expects a reference to a
subroutine. More details are given in the section on
"FITNESS FUNCTION".
*-type* This defines the type of the genome. Currently, AI::Genetic
supports only three types:
*bitvector*
Individuals of this type have genes that are bits. Each
gene can be in one of two possible states, on or off.
*listvector*
Each gene of a listvector individual can assume one
string value from a specified list of possible string
values.
*rangevector*
Each gene of a rangevector individual can assume one
integer value from a range of possible integer values.
Note that only integers are supported. The user can
always transform any desired fractional values by
multiplying and dividing by an appropriate power of 10.
Defaults to *bitvector*.
*-terminate*
This option allows the definition of a termination
subroutine. It expects a subroutine reference. This sub will
be called at the end of each generation with one argument:
the AI::Genetic object. Evolution terminates if the sub
returns a true value.
*$ga*->createStrategy(*strategy_name*, *sub_ref*)
This method allows the creation of a custom-made strategy to be used
during evolution. It expects a unique strategy name, and a
subroutine reference as arguments. The subroutine will be called
with one argument: the AI::Genetic object. It is expected to alter
the population at each generation. See the section on "STRATEGIES"
for more information.
*$ga*->init(*initArgs*)
This method initializes the population with random individuals. It
MUST be called before any call to *evolve()* or *inject()*. As a
side effect, any already existing individuals in the population are
deleted. It expects one argument, which depends on the type of
individuals:
o For bitvectors, the argument is simply the length of the
bitvector.
$ga->init(10);
this initializes a population where each individual has 10
genes.
o For listvectors, the argument is an anonymous list of lists. The
number of sub-lists is equal to the number of genes of each
individual. Each sub-list defines the possible string values
that the corresponding gene can assume.
$ga->init([
[qw/red blue green/],
[qw/big medium small/],
[qw/very_fat fat fit thin very_thin/],
]);
this initializes a population where each individual has 3 genes,
and each gene can assume one of the given values.
o For rangevectors, the argument is an anonymous list of lists.
The number of sub-lists is equal to the number of genes of each
individual. Each sub-list defines the minimum and maximum
integer values that the corresponding gene can assume.
$ga->init([
[1, 5],
[0, 20],
[4, 9],
]);
this initializes a population where each individual has 3 genes,
and each gene can assume an integer within the corresponding
range.
*$ga*->inject(*N*, ?*args*?)
This method can be used to add more individuals to the population.
New individuals can be randomly generated, or be explicitly
specified. The first argument specifies the number, *N*, of new
individuals to add. This can be followed by at most *N* arguments,
each of which is an anonymous list that specifies the genome of a
single individual to add. If the number of genomes given, *n*, is
less than *N*, then *N* - *n* random individuals are added for a
total of *N* new individuals. Random individuals are generated using
the same arguments passed to the *init()* method. For example:
$ga->inject(5,
[qw/red big thin/],
[qw/blue small fat/],
);
this adds 5 new individuals, 2 with the specified genetic coding,
and 3 randomly generated.
*$ga*->evolve(*strategy*, ?*num_generations*?)
This method causes the GA to evolve the population using the
specified strategy. A strategy name has to be specified as the first
argument. The second argument is optional and specifies the number
of generations to evolve. It defaults to 1. See the section on
( run in 0.718 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )