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

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.

Methods:

  • acceptUpload
  • endFitnessTest
  • endGeneration
  • examine
  • generatePopulation
  • getBestFitness
  • getBestIndividual
  • getCrossoverPercent
  • getCurrentIndividual
  • getCurrentIndividualIndex
  • getFitnessTestDuration
  • getGeneration
  • getGenerationLimit
  • getMigrationPercent
  • getMutationPercent
  • getPopulationSize
  • getRandomizePercent
  • getSpatialRadius
  • getTournamentSize
  • nonSpatialTournamentSelect
  • prepareForGeneration
  • report
  • reproduce
  • setCrossoverPercent
  • setFitnessTestDuration
  • setGenerationLimit
  • setIndividualClass
  • setMigrationHosts
  • setMigrationPercent
  • setMigrationPort
  • setMutationPercent
  • setPopulationSize
  • setRandomizePercent
  • setSeedIndividual
  • setSpatialRadius
  • setTournamentSize
  • spatialTournamentSelect
  • startFitnessTest
  • switchIndividual
  • tournamentSelect
    acceptUpload( self, migrants, other )


    endFitnessTest( self, individual )

    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 OBJECTGeneticAlgorithmIndividual:set-fitness.


    endGeneration( self, n )

    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( self, currentIndividual )

    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.


    generatePopulation( self )


    getBestFitness( self )

    Returns the best fitness seen so far.


    getBestIndividual( self )

    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.


    getCrossoverPercent( self )

    Returns the probability of crossover during reproduction.


    getCurrentIndividual( self )

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


    getCurrentIndividualIndex( self )

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


    getFitnessTestDuration( self )

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


    getGeneration( self )

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


    getGenerationLimit( self )

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


    getMigrationPercent( self )


    getMutationPercent( self )

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


    getPopulationSize( self )

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


    getRandomizePercent( self )

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


    getSpatialRadius( self )


    getTournamentSize( self )

    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.


    nonSpatialTournamentSelect( self )

    This method performs a tournament selection for reproduction. It is used internally and typically not called by any other object.


    prepareForGeneration( self, n )

    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( self, generation, bestIndividual, fitness )

    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.


    reproduce( self )


    setCrossoverPercent( self, percent )

    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%.


    setFitnessTestDuration( self, duration )

    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.


    setGenerationLimit( self, newLimit )

    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.


    setIndividualClass( self, className )

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


    setMigrationHosts( self, hosts )

    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.


    setMigrationPercent( self, percent )

    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.


    setMigrationPort( self, port )

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


    setMutationPercent( self, percent )

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


    setPopulationSize( self, size )

    Sets the number of individuals in the population to size.


    setRandomizePercent( self, percent )

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


    setSeedIndividual( self, theSeed )

    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.


    setSpatialRadius( self, n )

    Undocumented: it will be our little secret!


    setTournamentSize( self, tsize )

    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.


    spatialTournamentSelect( self, index )


    startFitnessTest( self, individual )

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


    switchIndividual( self )

    Switches to the next indivisual


    tournamentSelect( self, i )