These pages are auto-generated from self-documenting comments embedded in class files.
For more information on breve and steve, refer to the breve homepage.

## Object : GeneticAlgorithm

This class is included as part of the file GeneticAlgorithm.tz.
To use this class in a simulation, include the line "@use GeneticAlgorithm."

### Class description:

> The GeneticAlgorithm class allows you to set up a genetic algorithm, in which strategies can be evolved to solve a wide variety of problems.

> To run a genetic algorithm, you will need to a create custom subclass of this object, GeneticAlgorithm, and of its companion object GeneticProgrammingIndividual.

> Your subclass of GeneticAlgorithm must implement two important methods: start-fitness-test and end-fitness-test. These methods are automatically called at the beginning and end of the fitness tests respectively.

### Class methods:

> Getting and Setting Parameters for the Genetic Algorithm

> - get-best-fitness
> - get-best-individual
> - get-crossover-percent
> - get-current-individual
> - get-current-individual-index
> - get-fitness-test-duration
> - get-generation
> - get-generation-limit
> - get-migration-percent
> - get-mutation-percent
> - get-population-size
> - get-randomize-percent
> - get-tournament-size
> - set-crossover-percent
> - set-fitness-test-duration
> - set-generation-limit
> - set-individual-class
> - set-migration-hosts
> - set-migration-percent
> - set-migration-port
> - set-mutation-percent
> - set-population-size
> - set-randomize-percent
> - set-seed-individual
> - set-tournament-size

> Methods Used Internally by the Genetic Algorithm

> - switch-individual
> - tournament-select

> Methods for Cluster Migration

> - accept-upload

> Methods to Override in Custom Subclasses

> - end-fitness-test
> - end-generation
> - examine
> - prepare-for-generation
> - report
> - start-fitness-test

``

`end-fitness-test of individual (object)`

> In this method, you should perform any cleanup neccessary when the fitness test ends. You should also make sure that the individual's fitness value is set using set-fitness (GeneticAlgorithmIndividual).

`end-generation number n (int)`

> This method is called right when the generation is finished, before any of the reproduction takes place. This method provides an opportunity to examine the entire population of the generation after all fitness tests are run, and before the individuals are possibly destroyed through reproduction.

`examine individual currentIndividual (object)`

> Called automatically during each generation's report, this method examines and outputs information about an individual in the population. The default implementation simply prints out the object variable, but you may override this method to print out more information about the individual.

`get-best-fitness`

> Returns the best fitness seen so far.

`get-best-individual`

> Returns the best active individual. Note that at the end of each generation any individual, including the best, may be deleted and replaced with a new one, so be careful when this method is called and how it is used.

`get-crossover-percent`

> Returns the probability of crossover during reproduction.

`get-current-individual`

> Returns the current GeneticAlgorithmIndividual subclass instance being evaluated. See also get-current-individual-index.

`get-current-individual-index`

> Returns the index of the individual currently being tested. Returns -1 before any fitness tests have been run. See also get-current-individual.

`get-fitness-test-duration`

> Returns the duration of a single fitness test. This value can be set with the method set-test-duration. The default value is 20.

`get-generation`

> Returns the current generation. The generation count begins at 0.

`get-generation-limit`

> Returns the generation limit. See get-generation-limit for details.

``

`get-mutation-percent`

> Returns the percent probability of mutation during reproduction. The default value is 75%.

`get-population-size`

> Returns the size of the population. The default value is 30, and can be set with set-population-size.

`get-randomize-percent`

> Returns the percent probability of a new random individual during reproduction. The default value is 5%.

`get-tournament-size`

> Returns the tournament size. The tournament size specifies how many individuals are considered in a single selection "tournament". The larger the tournament size, the more competative selection becomes. The tournament size can be set with set-tournament-size. The default value is 5.

`prepare-for-generation number n (int)`

> This method is called when a generation is setup. The default implementation does nothing, but the method may be overriden in order to carry out any preparations necessary for a new generation.

`report at-generation generation (int) with-best-individual bestIndividual (object) with-average-fitness fitness (double)`

> Prints out a report of the progress at each generation, with the most fit object passed in as bestIndividual. The default implementation of this method simply prints out the generation number, best fitness and calls examine on the best individual, but you may override the method to print out any other desired information.

`set-crossover-percent to percent (int)`

> Sets the probability of crossover to percent%. This specifies the approximate percentage of agents to be generated through crossover during reproduction. Crossover is not enabled by default, so the default value is 0%.

`set-fitness-test-duration to duration (double)`

> Sets the duration of a single fitness test. Specifies that a single individual should be allowed to run for duration simulated seconds before assessing its fitness and switching to the next individual. The default value is 20.

`set-generation-limit to newLimit (int)`

> Sets the generation limit to newLimit. The simulation will end after newLimit generations have passed. If newLimit is 0, then the generation limit is disabled.

`set-individual-class to className (string)`

> Call this method to specify the class representing an individual in your genetic algorithm. className must be a string representing a subclass of GeneticAlgorithmIndividual.

`set-migration-hosts to hosts (list)`

> Sets a list of migration hosts for this object. This should be a list of strings containing hostnames of other machines running a genetic algorithm with the same simulation.

`set-migration-percent to percent (int)`

> Sets the probability of migration to percent%. This specifies the approximate percentage that individuals will migrate to another host during reproduction, if migration is enabled and migration hosts are specified using set-migration-hosts.

`set-migration-port to port (int)`

> Sets the port on which migration should occur. The default value of 59142 typically does not need to be changed.

`set-mutation-percent to percent (int)`

> Sets the probability of mutation to percent%. This specifies the approximate percentage of agents to be generated through mutation. The default value is 75%.

`set-population-size to size (int)`

> Sets the number of individuals in the population to size.

`set-randomize-percent to percent (int)`

> Sets the probability of creating a new random individual to percent%. The default value is 5%.

`set-seed-individual to theSeed (object)`

> The seed individual is used to start the genetic algorithm at a specfic location in the search space by using the seed individual's paramters as a starting point.

`set-tournament-size to tsize (int)`

> Sets the tournament size to tsize. The tournament size specifies how many individuals are considered in a single selection "tournament". The larger the tournament size, the more competative selection becomes. The default value is 5.

`start-fitness-test of individual (object)`

> Implement this method to perform any setup necessary when the fitness test begins.

`switch-individual`

> Switches to the next indivisual

``

Documentation created Thu Jul 3 18:18:12 2008