NAME

StringEvolver - A generic base critter class for use with Algorithm::Evolve

SYNOPSIS

package StringCritters;
use StringEvolver string_length => 50,
                  alphabet => [qw/A B C D/],
                  ...;
our @ISA = ('StringEvolver');

# override methods you want to change

# StringCritters is now a valid critter class

You can use this class as a base class any time your representation is a string gene.

USE ARGUMENTS

string_length

The length of strings to evolve. Defaults to 20.

alphabet

A reference to an array of characters. Defaults to [0,1].

reference_string

By default, fitness is measured as the number of character agreements to a reference string. However, if you are implementing a non-trivial string evolver, you will probably override the fitness method and this argument won't make a difference. It defaults to '1'x20.

mutation_rate

If this number is less than one, then it is the probablistic mutation rate for each character. If it is greater than or equal to one, then exactly that many mutations will be performed per child (so it must be an integer). Defaults to 0.05.

crossover_pts

The number of crossover points when performing crossover. See Algorithm::Evolve::Util for more information on crossover.

INHERITED METHODS

When used as a base class, the calling class inherit the following methods:

Class->new()

When used with an argument, the new critter is initialized with the argument as its string value. Otherwise, this method creates a random string within the alphabet.

$obj->mutate()

Mutates the critter's string gene according to the given mutation rate.

Class->crossover($obj1, $obj2)

Takes two critters and returns a random crossover of the two, according to the given number of crossover points.

$obj->fitness()

Returns the fitness of the critter, measured as the number of character agreements with a reference string. You will probably override this method.

$obj->value()

Returns the value of the critter's string gene.

SEE ALSO

Algorithm::Evolve, Algorithm::Evolve::Util, the rest of the examples/ directory.

AUTHOR

Algorithm::Evolve is written by Mike Rosulek <mike@mikero.com>. Feel free to contact me with comments, questions, patches, or whatever.

COPYRIGHT

Copyright (c) 2003 Mike Rosulek. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.