This is actually where the constructor for all PerlGP classes is defined, but it has been explained in more detail above.
Thanks to the magic of Perl's AUTOLOAD mechanism, we can use all valid attribute names as methods to get and set their values. So the usage is simply:
# getting my $prob = $individual->NodeMutationProb(); my $size = $population->PopulationSize(); # setting $algorithm->TournamentsSinceBest(0); $individual->Terminals({ NUM=>[0 .. 9], CHAR=>['a' .. 'z'] });
However, sometimes it's not convenient to use this notation, particularly during string interpolation or with +=, so you will often see direct access to the attributes in the object hash.
$algorithm->{Tournament}++; print "my file stem is $self->{DBFileStem}\n";
In order for this to mechanism to work, an object needs to know which attributes it has. It looks to see if the requested method name is a key in the object's hash table. The simplest way to define these is in the %defaults hash in the top level class definition file (e.g. Algorithm.pm). You can also ``reserve'' an attribute for later use with optionalParams(), which is equivalent to initialising the attribute with an undefined value.
Because the set routine returns $self, you can chain ``set'' calls like this:
$object->NodeMutationProb(0.01)->NodeXoverProb(0.02);
See the discussion for AUTOLOAD. Add a call to this method in the _init() routine (after the SUPER::_init() call - see GPPopulation.pm for an example) to reserve an attribute name so that the AUTOLOAD get/set routines will recognise it.
If you want to make sure that the user provides values for certain attributes in the constructor or top level _init() routine, then you can use this routine. See GeneticProgram::_init() for an example.