JGAP

org.jgap.gp.impl
Class GPConfiguration

java.lang.Object
  extended by org.jgap.Configuration
      extended by org.jgap.gp.impl.GPConfiguration
All Implemented Interfaces:
java.io.Serializable, Configurable

public class GPConfiguration
extends Configuration

Configuration for a GP.

Since:
3.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jgap.Configuration
PROPERTY_BFITFNC_INST, PROPERTY_EVENT_MGR_INST, PROPERTY_FITEVAL_INST, PROPERTY_FITFUNC_INST, PROPERTY_JGAPFACTORY_CLASS, PROPERTY_SAMPLE_CHROM_INST, S_CHROMOSOME_SIZE, S_CONFIGURATION, S_CONFIGURATION_HANDLER, S_CONFIGURATION_NAME, S_EVENT_MANAGER, S_FITNESS_EVALUATOR, S_FITNESS_FUNCTION, S_GENETIC_OPERATORS, S_MINPOPSIZE, S_NATURAL_SELECTORS, S_NONE, S_POPULATION_SIZE, S_POST, S_PRE, S_RANDOM_GENERATOR, S_SAMPLE_CHROM, S_SIZE, S_TOSTRING
 
Constructor Summary
GPConfiguration()
          Constructor.
 
Method Summary
 void addGeneticOperator(GeneticOperator a_operatorToAdd)
          Adds a genetic operator for use in this algorithm.
 void clearMemory()
          Clears the memory.
 void clearStack()
           
 CrossMethod getCrossMethod()
           
 double getCrossoverProb()
           
 IGPFitnessEvaluator getGPFitnessEvaluator()
           
 GPFitnessFunction getGPFitnessFunction()
           
 int getMaxCrossoverDepth()
           
 int getMaxInitDepth()
           
 double getNewChromsPercent()
           
 INodeValidator getNodeValidator()
           
 int getProgramCreationMaxtries()
           
 double getReproductionProb()
           
 INaturalGPSelector getSelectionMethod()
           
 boolean isStrictProgramCreation()
           
 java.lang.Object peekStack()
           
 java.lang.Object popFromStack()
           
 void pushToStack(java.lang.Object a_value)
           
 java.lang.Object readFromMemory(java.lang.String a_name)
          Reads a value from the internal memory.
 void setCrossoverProb(float a_crossoverProb)
           
 void setFitnessFunction(GPFitnessFunction a_functionToSet)
          Sets the fitness function to be used for this genetic algorithm.
 void setMaxCrossoverDepth(int a_maxCrossoverDepth)
           
 void setMaxInitDepth(int a_maxDepth)
           
 void setNewChromsPercent(double a_newChromsPercent)
           
 void setNodeValidator(INodeValidator a_nodeValidator)
          Sets the node validator.
 void setProgramCreationMaxTries(int a_maxtries)
           
 void setReproductionProb(float a_reproductionProb)
           
 void setStrictProgramCreation(boolean a_strict)
           
 int stackSize()
           
 void storeInMemory(java.lang.String a_name, java.lang.Object a_value)
          Stores a value in the internal memory.
 boolean validateNode(ProgramChromosome a_chrom, CommandGene a_node, int a_tries, int a_num, int a_recursLevel, java.lang.Class a_type, CommandGene[] a_functionSet, int a_depth, boolean a_grow)
          Validates a_node in the context of a_chrom.
 void verifyStateIsValid()
          Tests the state of this Configuration object to make sure it's valid.
 
Methods inherited from class org.jgap.Configuration
addNaturalSelector, checkProperty, getBulkFitnessFunction, getChromosomePool, getChromosomeSize, getConfigurationHandler, getEventManager, getFitnessEvaluator, getFitnessFunction, getGenerationNr, getGeneticOperators, getJGAPFactory, getMinimumPopSizePercent, getName, getNaturalSelector, getNaturalSelector, getNaturalSelectors, getNaturalSelectorsSize, getPopulationSize, getRandomGenerator, getSampleChromosome, getThreadKey, incrementGenerationNr, isKeepPopulationSizeConstant, isLocked, isPreserveFittestIndividual, lockSettings, makeKey, removeNaturalSelectors, reset, reset, resetProperty, resetProperty, setBulkFitnessFunction, setChromosomePool, setEventManager, setFitnessEvaluator, setFitnessFunction, setJGAPFactory, setKeepPopulationSizeConstant, setMinimumPopSizePercent, setName, setNaturalSelector, setPopulationSize, setPreservFittestIndividual, setRandomGenerator, setSampleChromosome, toString, verifyChangesAllowed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GPConfiguration

public GPConfiguration()
                throws InvalidConfigurationException
Constructor.

Throws:
InvalidConfigurationException
Since:
3.0
Method Detail

verifyStateIsValid

public void verifyStateIsValid()
                        throws InvalidConfigurationException
Description copied from class: Configuration
Tests the state of this Configuration object to make sure it's valid. This generally consists of verifying that required settings have, in fact, been set. If this object is not in a valid state, then an exception will be thrown detailing the reason the state is not valid.

Overrides:
verifyStateIsValid in class Configuration
Throws:
InvalidConfigurationException - if the state of this Configuration is not valid. The error message in the exception will detail the reason for invalidity

addGeneticOperator

public void addGeneticOperator(GeneticOperator a_operatorToAdd)
                        throws InvalidConfigurationException
Description copied from class: Configuration
Adds a genetic operator for use in this algorithm. Genetic operators represent evolutionary steps that, when combined, make up the evolutionary process. Examples of genetic operators are reproduction, crossover, and mutation. During the evolution process, all of the genetic operators added via this method are invoked in the order they were added. At least one genetic operator must be provided.

Overrides:
addGeneticOperator in class Configuration
Parameters:
a_operatorToAdd - The genetic operator to add.
Throws:
InvalidConfigurationException - if the genetic operator is null or if this Configuration object is locked

getCrossoverProb

public double getCrossoverProb()

setCrossoverProb

public void setCrossoverProb(float a_crossoverProb)

getReproductionProb

public double getReproductionProb()

setReproductionProb

public void setReproductionProb(float a_reproductionProb)

setNewChromsPercent

public void setNewChromsPercent(double a_newChromsPercent)

getNewChromsPercent

public double getNewChromsPercent()

getMaxCrossoverDepth

public int getMaxCrossoverDepth()

setMaxCrossoverDepth

public void setMaxCrossoverDepth(int a_maxCrossoverDepth)

getSelectionMethod

public INaturalGPSelector getSelectionMethod()

getCrossMethod

public CrossMethod getCrossMethod()

getMaxInitDepth

public int getMaxInitDepth()

setMaxInitDepth

public void setMaxInitDepth(int a_maxDepth)

pushToStack

public void pushToStack(java.lang.Object a_value)

popFromStack

public java.lang.Object popFromStack()

peekStack

public java.lang.Object peekStack()

stackSize

public int stackSize()

clearStack

public void clearStack()

storeInMemory

public void storeInMemory(java.lang.String a_name,
                          java.lang.Object a_value)
Stores a value in the internal memory.

Parameters:
a_name - named index of the memory cell
a_value - the value to store
Since:
3.0

readFromMemory

public java.lang.Object readFromMemory(java.lang.String a_name)
Reads a value from the internal memory.

Parameters:
a_name - named index of the memory cell to read out
Returns:
read value
Since:
3.0

clearMemory

public void clearMemory()
Clears the memory.

Since:
3.0

getGPFitnessFunction

public GPFitnessFunction getGPFitnessFunction()

setFitnessFunction

public void setFitnessFunction(GPFitnessFunction a_functionToSet)
                        throws InvalidConfigurationException
Sets the fitness function to be used for this genetic algorithm. The fitness function is responsible for evaluating a given Chromosome and returning a positive integer that represents its worth as a candidate solution. These values are used as a guide by the natural to determine which Chromosome instances will be allowed to move on to the next round of evolution, and which will instead be eliminated.

Parameters:
a_functionToSet - fitness function to be used
Throws:
InvalidConfigurationException - if the fitness function is null, or if this Configuration object is locked.
Since:
1.1

isStrictProgramCreation

public boolean isStrictProgramCreation()

setStrictProgramCreation

public void setStrictProgramCreation(boolean a_strict)

getProgramCreationMaxtries

public int getProgramCreationMaxtries()

setProgramCreationMaxTries

public void setProgramCreationMaxTries(int a_maxtries)

getGPFitnessEvaluator

public IGPFitnessEvaluator getGPFitnessEvaluator()
Returns:
the assigned FitnessEvaluator
Since:
2.0

validateNode

public boolean validateNode(ProgramChromosome a_chrom,
                            CommandGene a_node,
                            int a_tries,
                            int a_num,
                            int a_recursLevel,
                            java.lang.Class a_type,
                            CommandGene[] a_functionSet,
                            int a_depth,
                            boolean a_grow)
Validates a_node in the context of a_chrom. Considers the recursion level (a_recursLevel), the type needed (a_type) for the node, the functions available (a_functionSet) and the depth of the whole chromosome needed (a_depth), and whether grow mode is used (a_grow is true) or not.

Parameters:
a_chrom - the chromosome that will contain the node, if valid
a_node - the node selected and to be validated
a_tries - number of times the validator has been called, useful for stopping by returning true if the number exceeds a limit
a_num - the chromosome's index in the individual of this chromosome
a_recursLevel - level of recursion
a_type - the return type of the node needed
a_functionSet - the array of available functions
a_depth - the needed depth of the program chromosome
a_grow - true: use grow mode, false: use full mode
Returns:
true: node is valid; false: node is invalid
Since:
3.0

setNodeValidator

public void setNodeValidator(INodeValidator a_nodeValidator)
Sets the node validator. Also see method validateNode.

Parameters:
a_nodeValidator - sic
Since:
3.0

getNodeValidator

public INodeValidator getNodeValidator()
Returns:
the node validator set
Since:
3.0

JGAP