com.epochx.core
Class GPAbstractModel<TYPE>

java.lang.Object
  extended by com.epochx.core.GPAbstractModel<TYPE>
All Implemented Interfaces:
GPModel<TYPE>, CrossoverListener<TYPE>, ElitismListener<TYPE>, GenerationListener, InitialisationListener<TYPE>, LifeCycleListener<TYPE>, MutationListener<TYPE>, PoolSelectionListener<TYPE>, ReproductionListener<TYPE>, TerminationListener, CrossoverStatListener, GenerationStatListener, MutationStatListener, RunStatListener
Direct Known Subclasses:
CubicRegression, Even4Parity, Even5Parity, Even7Parity, Majority5, Majority9, Multiplexer11Bit, Multiplexer20Bit, Multiplexer37Bit, Multiplexer6Bit, QuarticRegression, SantaFeTrail

public abstract class GPAbstractModel<TYPE>
extends java.lang.Object
implements GPModel<TYPE>, GenerationStatListener, RunStatListener, CrossoverStatListener, MutationStatListener, LifeCycleListener<TYPE>

GPAbstractModel is a partial implementation of GPModel which provides sensible defaults for many of the necessary control parameters. It also provides a simple way of setting many values so an extending class isn't required to override all methods they wish to alter, and can instead use a simple setter method call.

Those methods that it isn't possible to provide a sensible default for, for example getFitness(CandidateProgram), getTerminals() and getFunctions(), are not implemented to force the extending class to consider their implementation.

See Also:
GPModel

Constructor Summary
GPAbstractModel()
          Construct a GPModel with a set of sensible defaults.
 
Method Summary
 boolean acceptCrossover(CandidateProgram<TYPE>[] parents, CandidateProgram<TYPE>[] children)
          Default implementation which accepts all crossovers.
 boolean acceptMutation(CandidateProgram<TYPE> parent, CandidateProgram<TYPE> child)
          Default implementation which accepts all mutations.
 void crossoverStats(java.lang.Object[] stats)
          Default implementation.
 void generationStats(int generation, java.lang.Object[] stats)
          Default implementation.
 Crossover<TYPE> getCrossover()
          Retrieves the implementation of Crossover to use to perform the genetic operation of crossover between 2 parents.
 double getCrossoverProbability()
          Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the crossover genetic operator, as opposed to mutation or reproduction.
 CrossoverStatField[] getCrossoverStatFields()
          Default implementation.
 CrossoverStatListener getCrossoverStatListener()
          Get a listener which will be informed of statistics about crossovers.
 GenerationStatListener getGenerationStatListener()
          Get a listener which will be informed of statistics about generations.
 GenerationStatField[] getGenStatFields()
          Default implementation.
 Initialiser<TYPE> getInitialiser()
          Retrieves the Initialiser which will generate the first generation population from which the evolution will proceed.
 int getInitialMaxDepth()
          Retrieves the maximum depth of CandidatePrograms allowed in the population after initialisation.
 LifeCycleListener<TYPE> getLifeCycleListener()
          Default implementation returns this model as the life cycle listener.
 int getMaxProgramDepth()
          Retrieves the maximum depth of CandidatePrograms allowed in the population after undergoing genetic operators.
 double getMutationProbability()
          Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the mutation genetic operator, as opposed to crossover or reproduction.
 MutationStatField[] getMutationStatFields()
          Default implementation.
 MutationStatListener getMutationStatListener()
          Get a listener which will be informed of statistics about mutations.
 Mutation<TYPE> getMutator()
          Retrieves the implementation of Mutator to use to perform the genetic operation of mutation on a CandidateProgram.
 int getNoElites()
          Retrieves the number of elites that should be copied straight to the next population.
 int getNoGenerations()
          Retrieves the number of generations that each run should use before terminating, unless prior termination occurs due to one of the other termination criterion.
 int getNoRuns()
          Retrieves the number of runs that should be carried out using this model as the basis.
 PoolSelector<TYPE> getPoolSelector()
          Retrieves the selector to use to construct a breeding pool from which parents can be selected using the parent selector returned by getProgramSelector() to undergo the genetic operators.
 int getPoolSize()
          Retrieves the size of the breeding pool to be used for parent selection when performing the genetic operators.
 int getPopulationSize()
          Retrieves the number of CandidatePrograms that should make up each generation.
 ProgramSelector<TYPE> getProgramSelector()
          Retrieves the selector to use to pick parents from either a pre-selected breeding pool (selected by the PoolSelector returned by getPoolSelector()) or the previous population for use as input to the genetic operators.
 double getReproductionProbability()
          Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the reproduction genetic operator, as opposed to crossover or mutation.
 RandomNumberGenerator getRNG()
          Returns the RandomNumberGenerator instance that should be used for the generation of random numbers throughout execution.
 RunStatField[] getRunStatFields()
          Default implementation.
 RunStatListener getRunStatListener()
          Get a listener which will be informed of statistics about runs.
 java.util.List<Node<TYPE>> getSyntax()
          Returns the union of calls to getTerminals() and getFunctions.
 double getTerminationFitness()
          The fitness score at which a run should be stopped.
 void mutationStats(java.lang.Object[] stats)
          Default implementation.
 CandidateProgram<TYPE>[] onCrossover(CandidateProgram<TYPE>[] parents, CandidateProgram<TYPE>[] children)
          Called after selection and crossover of 2 individuals.
 java.util.List<CandidateProgram<TYPE>> onElitism(java.util.List<CandidateProgram<TYPE>> elites)
          Called after selection of elites.
 void onFitnessTermination()
          Called on termination of the GE run where execution ended because of the successful identification of a CandidateProgram with a fitness equal to or lower than the models termination fitness parameter.
 void onGenerationStart()
          Called at the start of each generation.
 void onGenerationTermination()
          Called on termination of the GE run where execution ended because the requested number of generations was completed without identification of a CandidateProgram with a fitness equal to or lower than the models termination fitness parameter.
 java.util.List<CandidateProgram<TYPE>> onInitialisation(java.util.List<CandidateProgram<TYPE>> pop)
          Called after initialisation.
 CandidateProgram<TYPE> onMutation(CandidateProgram<TYPE> parent, CandidateProgram<TYPE> child)
          Called after selection and mutation of an individual program.
 java.util.List<CandidateProgram<TYPE>> onPoolSelection(java.util.List<CandidateProgram<TYPE>> pool)
          Called after selection of the breeding pool.
 CandidateProgram<TYPE> onReproduction(CandidateProgram<TYPE> child)
          Called after selection of an individual to be reproduced into the next generation.
 void runStats(int runNo, java.lang.Object[] stats)
          Default implementation.
 void setCrossover(Crossover<TYPE> crossover)
          Overwrites the default crossover operator.
 void setCrossoverProbability(double crossoverProbability)
          Overwrites the default crossover probability.
 void setCrossoverStatFields(CrossoverStatField[] crossoverStatFields)
          Set the crossover statistics that the given CrossoverStatListener will receive after each crossover operation.
 void setCrossoverStatListener(CrossoverStatListener crossoverStatListener)
          Overwrites the default listener for crossover statistics.
 void setGenerationStatListener(GenerationStatListener generationStatListener)
          Overwrites the default listener for generation statistics.
 void setGenStatFields(GenerationStatField[] generationStatFields)
          Set the generation statistics that the given GenerationStatListener will receive at the end of each generation.
 void setInitialiser(Initialiser<TYPE> initialiser)
          Overwrites the default initialiser.
 void setInitialMaxDepth(int maxInitialDepth)
          Overwrites the default max program tree depth allowed after initialisation is performed.
 void setLifeCycleListener(LifeCycleListener<TYPE> lifeCycleListener)
          Overwrites the default life cycle listener.
 void setMaxProgramDepth(int maxDepth)
          Overwrites the default max program tree depth allowed after genetic operators are performed.
 void setMutationProbability(double mutationProbability)
          Overwrites the default mutation probability.
 void setMutationStatFields(MutationStatField[] mutationStatFields)
          Set the mutation statistics that the given MutationStatListener will receive after each mutation operation.
 void setMutationStatListener(MutationStatListener mutationStatListener)
          Overwrites the default listener for mutation statistics.
 void setMutator(Mutation<TYPE> mutator)
          Overwrites the default mutator used to perform mutation.
 void setNoElites(int noElites)
          Overwrites the default number of elites to copy from one generation to the next.
 void setNoGenerations(int noGenerations)
          Overwrites the default number of generations.
 void setNoRuns(int noRuns)
          Overwrites the default number of runs.
 void setPoolSelector(PoolSelector<TYPE> poolSelector)
          Overwrites the default pool selector used to generate a mating pool.
 void setPoolSize(int poolSize)
          Overwrites the default pool size value.
 void setPopulationSize(int populationSize)
          Overwrites the default population size of CandidatePrograms.
 void setProgramSelector(ProgramSelector<TYPE> programSelector)
          Overwrites the default parent selector used to select parents to undergo a genetic operator from either a pool or the previous population.
 void setRNG(RandomNumberGenerator rng)
          Overwrites the default random number generator used to generate random numbers to control behaviour throughout a run.
 void setRunStatFields(RunStatField[] runStatFields)
          Set the run statistics that the given RunStatListener will receive at the end of each run.
 void setRunStatListener(RunStatListener runStatListener)
          Overwrites the default listener for run statistics.
 void setTerminationFitness(double terminationFitness)
          Overwrites the default fitness for run termination.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.epochx.core.GPModel
getFitness, getFunctions, getTerminals
 

Constructor Detail

GPAbstractModel

public GPAbstractModel()
Construct a GPModel with a set of sensible defaults. See the appropriate accessor method for information of each default value.

Method Detail

getInitialiser

public Initialiser<TYPE> getInitialiser()
Retrieves the Initialiser which will generate the first generation population from which the evolution will proceed.

Defaults to FullInitialiser in GPAbstractModel.

Specified by:
getInitialiser in interface GPModel<TYPE>
Returns:
the Initialiser to create the first population.

setInitialiser

public void setInitialiser(Initialiser<TYPE> initialiser)
Overwrites the default initialiser.

Parameters:
initialiser - the new Initialiser to use when generating the starting population.

getCrossover

public Crossover<TYPE> getCrossover()
Retrieves the implementation of Crossover to use to perform the genetic operation of crossover between 2 parents. The 2 parents to be crossed over will be selected using the parent selector returned by getProgramSelector().

Defaults to UniformPointCrossover in GPAbstractModel.

Specified by:
getCrossover in interface GPModel<TYPE>
Returns:
the implementation of Crossover that will perform the genetic operation of crossover.
See Also:
UniformPointCrossover, KozaCrossover

setCrossover

public void setCrossover(Crossover<TYPE> crossover)
Overwrites the default crossover operator.

Parameters:
crossover - the crossover to set

getMutator

public Mutation<TYPE> getMutator()
Retrieves the implementation of Mutator to use to perform the genetic operation of mutation on a CandidateProgram. The individual to be mutated will be selected using the program selector returned by getProgramSelector().

Defaults to SubtreeMutation in GPAbstractModel.

Specified by:
getMutator in interface GPModel<TYPE>
Returns:
the implementation of Mutator that will perform the genetic operation of mutation.

setMutator

public void setMutator(Mutation<TYPE> mutator)
Overwrites the default mutator used to perform mutation.

Parameters:
mutator - the mutator to set.

getProgramSelector

public ProgramSelector<TYPE> getProgramSelector()
Retrieves the selector to use to pick parents from either a pre-selected breeding pool (selected by the PoolSelector returned by getPoolSelector()) or the previous population for use as input to the genetic operators.

Defaults to RandomSelector in GPAbstractModel.

Specified by:
getProgramSelector in interface GPModel<TYPE>
Returns:
the ProgramSelector which should be used to pick parents for input to the genetic operators.
See Also:
TournamentSelector

setProgramSelector

public void setProgramSelector(ProgramSelector<TYPE> programSelector)
Overwrites the default parent selector used to select parents to undergo a genetic operator from either a pool or the previous population.

Parameters:
programSelector - the new ProgramSelector to be used when selecting parents for a genetic operator.

getPoolSelector

public PoolSelector<TYPE> getPoolSelector()
Retrieves the selector to use to construct a breeding pool from which parents can be selected using the parent selector returned by getProgramSelector() to undergo the genetic operators.

Defaults to TournamentSelector with a tournament size of 3 in GPAbstractModel.

Specified by:
getPoolSelector in interface GPModel<TYPE>
Returns:
a PoolSelector which can be used to construct a breeding pool, or null if a breeding pool shouldn't be used and instead parents should be picked straight from the previous population.
See Also:
TournamentSelector

setPoolSelector

public void setPoolSelector(PoolSelector<TYPE> poolSelector)
Overwrites the default pool selector used to generate a mating pool.

Parameters:
poolSelector - the new PoolSelector to be used when building a breeding pool.

getSyntax

public java.util.List<Node<TYPE>> getSyntax()
Returns the union of calls to getTerminals() and getFunctions.

Specified by:
getSyntax in interface GPModel<TYPE>
Returns:
the full syntax for use in building node trees.

getRNG

public RandomNumberGenerator getRNG()
Returns the RandomNumberGenerator instance that should be used for the generation of random numbers throughout execution.

Defaults to JavaRandom in GEAbstractModel.

Specified by:
getRNG in interface GPModel<TYPE>
Returns:
the RandomNumberGenerator to use for generating randomness.

setRNG

public void setRNG(RandomNumberGenerator rng)
Overwrites the default random number generator used to generate random numbers to control behaviour throughout a run.

Parameters:
rng - the random number generator to be used any time random behaviour is required.

getNoRuns

public int getNoRuns()
Retrieves the number of runs that should be carried out using this model as the basis. Each call to GPRun.run() will be with the same model so this is useful when multiple runs are necessary with the same control parameters for research purposes or otherwise in order to attain reliable results drawn from mean averages.

Defaults to 1 in GPAbstractModel.

Specified by:
getNoRuns in interface GPModel<TYPE>
Returns:
the number of times this model should be used to control GP runs.

setNoRuns

public void setNoRuns(int noRuns)
Overwrites the default number of runs.

Parameters:
noRuns - the new number of runs to execute with this model.

getNoGenerations

public int getNoGenerations()
Retrieves the number of generations that each run should use before terminating, unless prior termination occurs due to one of the other termination criterion.

Defaults to 50 in GPAbstractModel.

Specified by:
getNoGenerations in interface GPModel<TYPE>
Returns:
the number of generations that should be evolved in each run.

setNoGenerations

public void setNoGenerations(int noGenerations)
Overwrites the default number of generations.

Parameters:
noGenerations - the new number of generations to use within a run.

getPopulationSize

public int getPopulationSize()
Retrieves the number of CandidatePrograms that should make up each generation. The population at the start and end of each generation should always equal exactly this number.

Defaults to 500 in GPAbstractModel.

Specified by:
getPopulationSize in interface GPModel<TYPE>
Returns:
the number of CandidatePrograms per generation.

setPopulationSize

public void setPopulationSize(int populationSize)
Overwrites the default population size of CandidatePrograms.

Parameters:
populationSize - the new number of CandidatePrograms each generation should contain.

getPoolSize

public int getPoolSize()
Retrieves the size of the breeding pool to be used for parent selection when performing the genetic operators. If the pool size is equal to or less than zero, or if getPoolSelector() returns null, then no pool will be used and parent selection will take place directly from the previous population.

Defaults to 50 in GPAbstractModel.

Specified by:
getPoolSize in interface GPModel<TYPE>
Returns:
the size of the mating pool to build with the PoolSelector returned by getPoolSelector() which will be used for parent selection.

setPoolSize

public void setPoolSize(int poolSize)
Overwrites the default pool size value.

Parameters:
poolSize - the new size of the mating pool to use.

getNoElites

public int getNoElites()
Retrieves the number of elites that should be copied straight to the next population. This number is distinct from the reproduction operator. Elites are generally picked as the very best programs in a generation, thus a number of elites of 1 or more will always retain the best program found so far, through to the last generation.

Defaults to 10 in GPAbstractModel.

Specified by:
getNoElites in interface GPModel<TYPE>
Returns:
the number of elites that should be copied through from one generation to the next.

setNoElites

public void setNoElites(int noElites)
Overwrites the default number of elites to copy from one generation to the next.

Parameters:
noElites - the new number of elites to copy across from one population to the next.

getInitialMaxDepth

public int getInitialMaxDepth()
Retrieves the maximum depth of CandidatePrograms allowed in the population after initialisation. The exact way in which the implementation ensures this depth is kept to may vary.

Defaults to 6 in GPAbstractModel.

Specified by:
getInitialMaxDepth in interface GPModel<TYPE>
Returns:
the maximum depth of CandidatePrograms to be allowed in the population after initialisation.

setInitialMaxDepth

public void setInitialMaxDepth(int maxInitialDepth)
Overwrites the default max program tree depth allowed after initialisation is performed.

Parameters:
maxInitialDepth - the new max program tree depth to use.

getMaxProgramDepth

public int getMaxProgramDepth()
Retrieves the maximum depth of CandidatePrograms allowed in the population after undergoing genetic operators. The exact way in which CandidatePrograms deeper than this limit are dealt with may vary, but they will not be allowed to remain into the next generation unaltered.

Defaults to 17 in GPAbstractModel.

Specified by:
getMaxProgramDepth in interface GPModel<TYPE>
Returns:
the maximum depth of CandidatePrograms to be allowed in the population after genetic operators.

setMaxProgramDepth

public void setMaxProgramDepth(int maxDepth)
Overwrites the default max program tree depth allowed after genetic operators are performed.

Parameters:
maxDepth - the new max program tree depth to use.

getCrossoverProbability

public double getCrossoverProbability()
Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the crossover genetic operator, as opposed to mutation or reproduction.

Within one generation approximately Pc proportion of the CandidatePrograms will have been created through crossover, Pm through mutation and Pr through reproduction. Where Pc, Pm, Pr are the values returned by getCrossoverProbability(), getMutationProbability() and getReproductionProbability() respectively. The sum of the calls to getCrossoverProbability(), getReproductionProbability() and getMutationProbability() should total 1.0.

Defaults to 0.9 in GPAbstractModel to represent a 90% chance.

Specified by:
getCrossoverProbability in interface GPModel<TYPE>
Returns:
the probability of choosing the crossover genetic operator at each iteration when constructing the next population.

setCrossoverProbability

public void setCrossoverProbability(double crossoverProbability)
Overwrites the default crossover probability.

Parameters:
crossoverProbability - the new crossover probability to use.

getMutationProbability

public double getMutationProbability()
Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the mutation genetic operator, as opposed to crossover or reproduction.

Within one generation approximately Pc proportion of the CandidatePrograms will have been created through crossover, Pm through mutation and Pr through reproduction. Where Pc, Pm, Pr are the values returned by getCrossoverProbability(), getMutationProbability() and getReproductionProbability() respectively. The sum of the calls to getCrossoverProbability(), getReproductionProbability() and getMutationProbability() should total 1.0.

Defaults to 0.0 in GPAbstractModel to represent a 0% chance.

Specified by:
getMutationProbability in interface GPModel<TYPE>
Returns:
the probability of choosing the mutation genetic operator at each iteration when constructing the next population.

setMutationProbability

public void setMutationProbability(double mutationProbability)
Overwrites the default mutation probability.

Parameters:
mutationProbability - the new mutation probability to use.

getReproductionProbability

public double getReproductionProbability()
Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the reproduction genetic operator, as opposed to crossover or mutation.

Within one generation approximately Pc proportion of the CandidatePrograms will have been created through crossover, Pm through mutation and Pr through reproduction. Where Pc, Pm, Pr are the values returned by getCrossoverProbability(), getMutationProbability() and getReproductionProbability() respectively. The sum of the calls to getCrossoverProbability(), getReproductionProbability() and getMutationProbability() should total 1.0.

Automatically calculates the reproduction probability based upon the crossover and mutation probabilities as all three together must add up to 100%.

Specified by:
getReproductionProbability in interface GPModel<TYPE>
Returns:
the probability of choosing the reproduction genetic operator at each iteration when constructing the next population.

getTerminationFitness

public double getTerminationFitness()
The fitness score at which a run should be stopped. Returning a negative value will result in no termination based upon fitness.

Defaults to 0.0 in GPAbstractModel.

Specified by:
getTerminationFitness in interface GPModel<TYPE>
Returns:
the fitness score at which a run should be terminated. A fitness of this or less will result in termination.

setTerminationFitness

public void setTerminationFitness(double terminationFitness)
Overwrites the default fitness for run termination.

Parameters:
terminationFitness - the new fitness below which a run will be terminated.

acceptCrossover

public boolean acceptCrossover(CandidateProgram<TYPE>[] parents,
                               CandidateProgram<TYPE>[] children)
Default implementation which accepts all crossovers.

Specified by:
acceptCrossover in interface GPModel<TYPE>
Parameters:
parents - The programs that were crossed over to create the given children.
children - The children that resulted from the parents being crossed over.
Returns:
True if the crossover operation should proceed, false if it is rejected and should be retried with new parents.

acceptMutation

public boolean acceptMutation(CandidateProgram<TYPE> parent,
                              CandidateProgram<TYPE> child)
Default implementation which accepts all mutations.

Specified by:
acceptMutation in interface GPModel<TYPE>
Parameters:
parent - The program before the mutation operation.
child - The program after the mutation operation has been carried out.
Returns:
True if the mutation operation should proceed, false if it is rejected and should be retried with a new parent.

getRunStatListener

public RunStatListener getRunStatListener()
Get a listener which will be informed of statistics about runs. The listener will be queried for what fields are of interest, with those statistics passed to the runStats method in the same order at the end of each run.

Defaults to this model object.

Specified by:
getRunStatListener in interface GPModel<TYPE>
Returns:
A RunStatListener to handle run statistics.

setRunStatListener

public void setRunStatListener(RunStatListener runStatListener)
Overwrites the default listener for run statistics.

Parameters:
runStatListener - the run stat listener to set.

getGenerationStatListener

public GenerationStatListener getGenerationStatListener()
Get a listener which will be informed of statistics about generations. The listener will be queried for what fields are of interest, with those statistics passed to the generationStats method in the same order after each generation.

Defaults to this model object.

Specified by:
getGenerationStatListener in interface GPModel<TYPE>
Returns:
A GenerationStatListener to handle generation statistics.

setGenerationStatListener

public void setGenerationStatListener(GenerationStatListener generationStatListener)
Overwrites the default listener for generation statistics.

Parameters:
generationStatListener - the generation stat listener to set.

getCrossoverStatListener

public CrossoverStatListener getCrossoverStatListener()
Get a listener which will be informed of statistics about crossovers. The listener will be queried for what fields are of interest, with those statistics passed to the crossoverStats method in the same order after each crossover operation.

Defaults to this model object.

Specified by:
getCrossoverStatListener in interface GPModel<TYPE>
Returns:
A CrossoverStatListener to handle crossover statistics.

setCrossoverStatListener

public void setCrossoverStatListener(CrossoverStatListener crossoverStatListener)
Overwrites the default listener for crossover statistics.

Parameters:
crossoverStatListener - the crossover stat listener to set.

getMutationStatListener

public MutationStatListener getMutationStatListener()
Get a listener which will be informed of statistics about mutations. The listener will be queried for what fields are of interest, with those statistics passed to the mutationStats method in the same order after each mutation operation.

Defaults to this model object.

Specified by:
getMutationStatListener in interface GPModel<TYPE>
Returns:
A MutationStatListener to handle mutation statistics.

setMutationStatListener

public void setMutationStatListener(MutationStatListener mutationStatListener)
Overwrites the default listener for mutation statistics.

Parameters:
mutationStatListener - the mutation stat listener to set.

getRunStatFields

public RunStatField[] getRunStatFields()
Default implementation. No fields are requested, the overriding class is expected to override this method or call the setter method IF it wants to receive information about the runs.

Typically it is the model that receives the statistics but this can be overridden by returning a different RunStatListener in the getRunStatListener() method. The runStats method of this object will then be called at the end of each run with these requested statistics.

Specified by:
getRunStatFields in interface RunStatListener
Returns:
An array of RunStatFields that this listener wants to listen for which will be passed to the runStats array after each run is completed.

setRunStatFields

public void setRunStatFields(RunStatField[] runStatFields)
Set the run statistics that the given RunStatListener will receive at the end of each run.

Parameters:
runStatFields - an array of RunStatFields that indicate the statistics fields that the RunStatListener will receive. The fields will be delivered in the same order as given here.

runStats

public void runStats(int runNo,
                     java.lang.Object[] stats)
Default implementation. If any run stats fields have been requested then they are printed to the console separated by tabs. In addition to the statistics, the first column will contain the run number.

Specified by:
runStats in interface RunStatListener
Parameters:
runNo - the run number of the current run. Runs are indexed from zero (0).
stats - an array of the statistics that were requested, given in the order that they were requested. The data type of each of the stats fields varies according to the field and is specified in the JavaDoc of the RunStatField enum.

getGenStatFields

public GenerationStatField[] getGenStatFields()
Default implementation. No fields are requested, the overriding class is expected to override this method or call the setter method IF it wants to receive information about generations.

Typically it is the model that receives the statistics but this can be overridden by returning a different GenerationStatListener in the getGenerationStatListener() method. The genenerationStats method of this object will then be called at the end of each generation with these requested statistics.

Specified by:
getGenStatFields in interface GenerationStatListener

setGenStatFields

public void setGenStatFields(GenerationStatField[] generationStatFields)
Set the generation statistics that the given GenerationStatListener will receive at the end of each generation.

Parameters:
generationStatFields - an array of GenerationStatFields that indicate the statistics fields that the GenerationStatListener will receive. The fields will be delivered in the same order as given here.

generationStats

public void generationStats(int generation,
                            java.lang.Object[] stats)
Default implementation. If any generation stats fields have been requested then they are printed to the console separated by tabs. In addition to the statistics, the first column will contain the generation number.

Specified by:
generationStats in interface GenerationStatListener
Parameters:
generation - the generation number of the current run. The first generation in a run will be zero (0), which references the population immediately after initialisation.
stats - an array of the statistics that were requested, given in the order that they were requested. The data type of each of the stats fields varies according to the field and is specified in the JavaDoc of the GenerationStatField enum.

getCrossoverStatFields

public CrossoverStatField[] getCrossoverStatFields()
Default implementation. No fields are requested, the overriding class is expected to override this method or call the setter method IF it wants to receive information about each crossover operation.

Typically it is the model that receives the statistics but this can be overridden by returning a different CrossoverStatListener in the getCrossoverStatListener() method. The crossoverStats method of this object will then be called at the end of each run with these requested statistics.

Specified by:
getCrossoverStatFields in interface CrossoverStatListener

setCrossoverStatFields

public void setCrossoverStatFields(CrossoverStatField[] crossoverStatFields)
Set the crossover statistics that the given CrossoverStatListener will receive after each crossover operation.

Parameters:
crossoverStatFields - an array of CrossoverStatFields that indicate the statistics fields that the CrossoverStatListener will receive. The fields will be delivered in the same order as given here.

crossoverStats

public void crossoverStats(java.lang.Object[] stats)
Default implementation. Does nothing. This is implemented here rather than being abstract to remove the need for the user to extend it if they are not interested in crossover stats.

Specified by:
crossoverStats in interface CrossoverStatListener
Parameters:
stats - an array of the statistics that were requested, given in the order that they were requested. The data type of each of the stats fields varies according to the field and is specified in the JavaDoc of the CrossoverStatField enum.

getMutationStatFields

public MutationStatField[] getMutationStatFields()
Default implementation. No fields are requested, the overriding class is expected to override this method or call the setter method IF it wants to receive information about each mutation operation.

Typically it is the model that receives the statistics but this can be overridden by returning a different MutationStatListener in the getMutationStatListener() method. The mutationStats method of this object will then be called at the end of each run with these requested statistics.

Specified by:
getMutationStatFields in interface MutationStatListener

setMutationStatFields

public void setMutationStatFields(MutationStatField[] mutationStatFields)
Set the mutation statistics that the given MutationStatListener will receive after each mutation operation.

Parameters:
mutationStatFields - an array of MutationStatFields that indicate the statistics fields that the MutationStatListener will receive. The fields will be delivered in the same order as given here.

mutationStats

public void mutationStats(java.lang.Object[] stats)
Default implementation. Does nothing. This is implemented here rather than being abstract to remove the need for the user to extend it if they're not interested in mutation stats.

Specified by:
mutationStats in interface MutationStatListener
Parameters:
stats - an array of the statistics that were requested, given in the order that they were requested. The data type of each of the stats fields varies according to the field and is specified in the JavaDoc of the MutationStatField enum.

getLifeCycleListener

public LifeCycleListener<TYPE> getLifeCycleListener()
Default implementation returns this model as the life cycle listener. By default all the listener methods will confirm the events though. Override the individual life cycle methods to add extra functionality in the model, or override this method to return a different life cycle listener.

Specified by:
getLifeCycleListener in interface GPModel<TYPE>
Returns:
the LifeCycleListener to inform of all events during the GP life cycle.

setLifeCycleListener

public void setLifeCycleListener(LifeCycleListener<TYPE> lifeCycleListener)
Overwrites the default life cycle listener.

Parameters:
lifeCycleListener - the object that should be informed about life cycle events as they happen.

onInitialisation

public java.util.List<CandidateProgram<TYPE>> onInitialisation(java.util.List<CandidateProgram<TYPE>> pop)
Called after initialisation.

Default implementation confirms the initialised population by returning the given population argument.

Specified by:
onInitialisation in interface InitialisationListener<TYPE>
Parameters:
pop - the newly initialised population.
Returns:
the population of CandidatePrograms to continue with as the newly initialised population, or null if initialisation should be rerun.

onElitism

public java.util.List<CandidateProgram<TYPE>> onElitism(java.util.List<CandidateProgram<TYPE>> elites)
Called after selection of elites. If the number of elites to use is set by the model to <=0, then this method will still be called at the appropriate time, but with an empty list.

Default implementation confirms the selected elites by returning the given list of elites.

Specified by:
onElitism in interface ElitismListener<TYPE>
Parameters:
elites - the selection of chosen elites.
Returns:
a List of CandidatePrograms to use as the set of elites. Note that it is not appropriate to return a value of null and this will cause undefined behaviour.

onPoolSelection

public java.util.List<CandidateProgram<TYPE>> onPoolSelection(java.util.List<CandidateProgram<TYPE>> pool)
Called after selection of the breeding pool. If the size of the breeding pool is set in the model to <=0, then this method will still be called at the appropriate time, but with a list containing every program in the population. The population essentially becomes the breeding pool in this circumstance.

Default implementation confirms the selected breeding pool by returning the given list of programs.

Specified by:
onPoolSelection in interface PoolSelectionListener<TYPE>
Parameters:
pool - the suggested breeding pool of programs.
Returns:
the breeding pool of CandidatePrograms that should actually be used, or null if breeding pool selection should be repeated.

onCrossover

public CandidateProgram<TYPE>[] onCrossover(CandidateProgram<TYPE>[] parents,
                                            CandidateProgram<TYPE>[] children)
Called after selection and crossover of 2 individuals.

Default implementation confirms the crossover operation by returning the given array of children.

Specified by:
onCrossover in interface CrossoverListener<TYPE>
Parameters:
parents - the programs that were selected to undergo crossover.
children - the programs that were generated as a result of the crossover operation.
Returns:
an array of CandidatePrograms to be used as the children of the crossover operation, or null if the crossover should be reverted.

onMutation

public CandidateProgram<TYPE> onMutation(CandidateProgram<TYPE> parent,
                                         CandidateProgram<TYPE> child)
Called after selection and mutation of an individual program.

Default implementation confirms the mutation operation by returning the given child program.

Specified by:
onMutation in interface MutationListener<TYPE>
Parameters:
parent - the program that was selected to undergo mutation.
child - the resultant program from the parent undergoing mutation.
Returns:
a CandidateProgram that should be considered the result of a mutation operation, or null if the mutation should be reverted.

onReproduction

public CandidateProgram<TYPE> onReproduction(CandidateProgram<TYPE> child)
Called after selection of an individual to be reproduced into the next generation.

Default implementation confirms the reproduction operation by returning the given selected program.

Specified by:
onReproduction in interface ReproductionListener<TYPE>
Parameters:
child - the program that was selected to be reproduced.
Returns:
a CandidateProgram that should be used as the reproduced program and inserted into the next population.

onGenerationStart

public void onGenerationStart()
Called at the start of each generation. Note that this method is called before the generation statistics are generated so any generation statistics will be created based upon the population returned here.

Default implementation does nothing.

Specified by:
onGenerationStart in interface GenerationListener

onFitnessTermination

public void onFitnessTermination()
Called on termination of the GE run where execution ended because of the successful identification of a CandidateProgram with a fitness equal to or lower than the models termination fitness parameter.

Default implementation does nothing.

Specified by:
onFitnessTermination in interface TerminationListener

onGenerationTermination

public void onGenerationTermination()
Called on termination of the GE run where execution ended because the requested number of generations was completed without identification of a CandidateProgram with a fitness equal to or lower than the models termination fitness parameter.

Default implementation does nothing.

Specified by:
onGenerationTermination in interface TerminationListener