org.jgap.gp.impl
Class GPConfiguration
- java.lang.Object
-
- org.jgap.Configuration
-
- org.jgap.gp.impl.GPConfiguration
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Configurable, ICloneable
public class GPConfiguration extends Configuration
Configuration for a GP.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jgap.Configuration
Configuration.ConfigurationConfigurable
-
-
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
Constructors Constructor and Description GPConfiguration()Constructor utilizing the FitnessProportionateSelection.GPConfiguration(INaturalGPSelector a_selectionMethod)Constructor utilizing the FitnessProportionateSelection.GPConfiguration(java.lang.String a_name)Constructs a configuration with an informative name but without a unique ID.GPConfiguration(java.lang.String a_id, java.lang.String a_name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddGeneticOperator(GeneticOperator a_operatorToAdd)Adds a genetic operator for use in this algorithm.voidclearMemory()Clears the memory.voidclearStack()java.lang.Objectclone()intcompareTo(java.lang.Object a_other)The compareTo-method.voidcreateMatrix(java.lang.String a_name, int a_cols, int a_rows)Creates an instance of a matrix with a unique name.booleanequals(java.lang.Object a_other)Compares this entity against the specified object.voidflagMaxNodeWarningPrinted()See ProgramChromosome.growOrFull(...) and GPGenotype.evolve().CrossMethodgetCrossMethod()doublegetCrossoverProb()doublegetDynamizeArityProb()doublegetFunctionProb()IGPFitnessEvaluatorgetGPFitnessEvaluator()GPFitnessFunctiongetGPFitnessFunction()IGPInitStrategygetInitStrategy()IJGAPFactorygetJGAPFactory()char[][]getMatrix(java.lang.String a_name)Retrieves a named matrix.intgetMaxCrossoverDepth()intgetMaxInitDepth()intgetMemorySize()intgetMinInitDepth()doublegetMutationProb()doublegetNewChromsPercent()INodeValidatorgetNodeValidator()intgetProgramCreationMaxtries()IGPProgramgetPrototypeProgram()doublegetReproductionProb()INaturalGPSelectorgetSelectionMethod()VariablegetVariable(java.lang.String a_varName)booleanisMaxNodeWarningPrinted()booleanisNoCommandGeneCloning()booleanisStrictProgramCreation()booleanisUseProgramCache()booleanisVerifyPrograms()GPConfigurationnewInstanceGP(java.lang.String a_id, java.lang.String a_name)Creates a new GPConfiguration instance by cloning.java.lang.ObjectpeekStack()java.lang.ObjectpopFromStack()voidpushToStack(java.lang.Object a_value)GPProgramInfoputToProgramCache(GPProgram a_prog)voidputVariable(Variable a_var)Stores a Variable.java.lang.ObjectreadFromMemory(java.lang.String a_name)Reads a value from the internal memory.java.lang.ObjectreadFromMemoryIfExists(java.lang.String a_name)java.lang.ObjectreadIndexedMemory(int a_index)Reads a value from the internal indexed memory.charreadMatrix(java.lang.String a_name, int a_col, int a_row)Reads a matrix cell and returns the value.java.lang.ObjectreadMatrixMemory(int a_x, int a_y)Reads a value from the internal matrix memory.GPProgramInforeadProgramCache(GPProgram a_prog)voidresetMatrix(java.lang.String a_name, char a_filler)Resets the matrix by filling it with a given character.voidsetCrossoverMethod(CrossMethod a_method)Sets the crossover method to use.voidsetCrossoverProb(float a_crossoverProb)voidsetDynamizeArityProb(float a_dynArityProb)voidsetFitnessEvaluator(IGPFitnessEvaluator a_fitnessEvaluator)Set the fitness evaluator (deciding if a given fitness value is better when it's higher or better when it's lower).voidsetFitnessFunction(GPFitnessFunction a_functionToSet)Sets the fitness function to be used for this genetic algorithm.voidsetFunctionProb(double a_functionProb)voidsetGPFitnessEvaluator(IGPFitnessEvaluator a_evaluator)Sets a GP fitness evaluator, such as org.jgap.gp.impl.DefaultGPFitnessEvaluator.voidsetInitStrategy(IGPInitStrategy a_strategy)voidsetMatrix(java.lang.String a_name, int a_col, int a_row, char a_value)Sets a matrix field with a value.voidsetMaxCrossoverDepth(int a_maxCrossoverDepth)voidsetMaxInitDepth(int a_maxDepth)voidsetMinInitDepth(int a_minDepth)voidsetMutationProb(float a_mutationProb)voidsetNewChromsPercent(double a_newChromsPercent)voidsetNoCommandGeneCloning(boolean a_noCommandGeneCloning)Decide whether to clone command genes when creating a new GP program in ProgramChromosome.voidsetNodeValidator(INodeValidator a_nodeValidator)Sets the node validator.voidsetProgramCreationMaxTries(int a_maxtries)voidsetPrototypeProgram(IGPProgram a_program)voidsetReproductionProb(float a_reproductionProb)voidsetSelectionMethod(INaturalGPSelector a_method)Sets the selection method to use.voidsetStrictProgramCreation(boolean a_strict)voidsetUseProgramCache(boolean a_useCache)voidsetVerifyPrograms(boolean a_verify)intstackSize()CultureMemoryCellstoreIndexedMemory(int a_index, java.lang.Object a_value)Stores a value in the internal indexed memory.voidstoreInMemory(java.lang.String a_name, java.lang.Object a_value)Stores a value in the internal memory.CultureMemoryCellstoreMatrixMemory(int a_x, int a_y, java.lang.Object a_value)Stores a value in the internal matrix memory.booleanvalidateNode(ProgramChromosome a_chrom, CommandGene a_node, CommandGene a_rootNode, int a_tries, int a_num, int a_recurseLevel, java.lang.Class a_type, CommandGene[] a_functionSet, int a_depth, boolean a_grow, int a_childIndex, boolean a_fullProgram)Validates a_node in the context of a_chrom.voidverifyStateIsValid()Tests the state of this Configuration object to make sure it's valid.-
Methods inherited from class org.jgap.Configuration
addNaturalSelector, getBreeder, getBulkFitnessFunction, getChromosomePool, getChromosomeSize, getConfigurationHandler, getEventManager, getFitnessEvaluator, getFitnessFunction, getGenerationNr, getGeneticOperators, getId, getMinimumPopSizePercent, getMonitor, getName, getNaturalSelector, getNaturalSelector, getNaturalSelectors, getNaturalSelectorsSize, getPopulationSize, getRandomGenerator, getSampleChromosome, getSelectFromPrevGen, incrementGenerationNr, isAlwaysCalculateFitness, isKeepPopulationSizeConstant, isLocked, isPreserveFittestIndividual, isUniqueKeysActive, lockSettings, newInstance, removeNaturalSelectors, reset, reset, resetProperty, resetProperty, setAlwaysCaculateFitness, setBreeder, setBulkFitnessFunction, setChromosomePool, setEventManager, setFitnessEvaluator, setFitnessFunction, setJGAPFactory, setKeepPopulationSizeConstant, setMinimumPopSizePercent, setMonitor, setName, setNaturalSelector, setPopulationSize, setPreservFittestIndividual, setRandomGenerator, setSampleChromosome, setSelectFromPrevGen, setUniqueKeysActive, toString
-
-
-
-
Constructor Detail
-
GPConfiguration
public GPConfiguration() throws InvalidConfigurationExceptionConstructor utilizing the FitnessProportionateSelection.- Throws:
InvalidConfigurationException- Since:
- 3.0
-
GPConfiguration
public GPConfiguration(java.lang.String a_id, java.lang.String a_name) throws InvalidConfigurationException- Throws:
InvalidConfigurationException
-
GPConfiguration
public GPConfiguration(java.lang.String a_name) throws InvalidConfigurationExceptionConstructs a configuration with an informative name but without a unique ID. This practically prevents more than one configurations to be instantiated within the same thread.- Parameters:
a_name- informative name of the configuration, may be null- Throws:
InvalidConfigurationException
-
GPConfiguration
public GPConfiguration(INaturalGPSelector a_selectionMethod) throws InvalidConfigurationException
Constructor utilizing the FitnessProportionateSelection.- Parameters:
a_selectionMethod- the selection method to use- Throws:
InvalidConfigurationException- Since:
- 3.1
-
-
Method Detail
-
setGPFitnessEvaluator
public void setGPFitnessEvaluator(IGPFitnessEvaluator a_evaluator)
Sets a GP fitness evaluator, such as org.jgap.gp.impl.DefaultGPFitnessEvaluator.- Parameters:
a_evaluator- the fitness evaluator to set- Since:
- 3.1
-
setSelectionMethod
public void setSelectionMethod(INaturalGPSelector a_method)
Sets the selection method to use.- Parameters:
a_method- the selection method to use- Since:
- 3.1
-
setCrossoverMethod
public void setCrossoverMethod(CrossMethod a_method)
Sets the crossover method to use.- Parameters:
a_method- the crossover method to use- Since:
- 3.1
-
verifyStateIsValid
public void verifyStateIsValid() throws InvalidConfigurationExceptionDescription copied from class:ConfigurationTests 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:
verifyStateIsValidin classConfiguration- 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:ConfigurationAdds 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:
addGeneticOperatorin classConfiguration- 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)
-
getMutationProb
public double getMutationProb()
- Returns:
- probability for mutation of a node during growing a program
- Since:
- 3.3.1
-
setMutationProb
public void setMutationProb(float a_mutationProb)
- Parameters:
a_mutationProb- probability for mutation of a node during growing a program- Since:
- 3.3.1
-
getDynamizeArityProb
public double getDynamizeArityProb()
- Returns:
- probability for dynamizing the arity of a node during growing a program
- Since:
- 3.4
-
setDynamizeArityProb
public void setDynamizeArityProb(float a_dynArityProb)
- Parameters:
a_dynArityProb- probability for dynamizing the arity of a node during growing a program- Since:
- 3.4
-
setFunctionProb
public void setFunctionProb(double a_functionProb)
- Parameters:
a_functionProb- probability that a function instead of a terminal is chosen in crossing over (between 0 and 1)- Since:
- 3.2
-
getFunctionProb
public double getFunctionProb()
- Returns:
- probability that a function instead of a terminal is chosen in crossing over
- Since:
- 3.2
-
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)
-
getMinInitDepth
public int getMinInitDepth()
-
setMinInitDepth
public void setMinInitDepth(int a_minDepth)
-
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 cella_value- the value to store- Since:
- 3.0
-
createMatrix
public void createMatrix(java.lang.String a_name, int a_cols, int a_rows)Creates an instance of a matrix with a unique name.- Parameters:
a_name- the name of the matrixa_cols- number of columns the matrix should havea_rows- number of rows the matrix should have- Since:
- 3.4.3
-
setMatrix
public void setMatrix(java.lang.String a_name, int a_col, int a_row, char a_value)Sets a matrix field with a value.- Parameters:
a_name- the name of the matrixa_col- column in the matrixa_row- row in the matrixa_value- the value to set in the matrix at given column and row- Since:
- 3.4.3
-
resetMatrix
public void resetMatrix(java.lang.String a_name, char a_filler)Resets the matrix by filling it with a given character.- Parameters:
a_name- the name of the matrixa_filler- the character to fill the whole matrix with- Since:
- 3.4.3
-
readMatrix
public char readMatrix(java.lang.String a_name, int a_col, int a_row)Reads a matrix cell and returns the value.- Parameters:
a_name- the name of the matrixa_col- the column to reada_row- the row to read- Returns:
- the value in the matrix
- Since:
- 3.4.3
-
getMatrix
public char[][] getMatrix(java.lang.String a_name)
Retrieves a named matrix.- Parameters:
a_name- the name of the matrix- Returns:
- the matrix itself
- Since:
- 3.4.3
-
storeMatrixMemory
public CultureMemoryCell storeMatrixMemory(int a_x, int a_y, java.lang.Object a_value)
Stores a value in the internal matrix memory.- Parameters:
a_x- the first coordinate of the matrix (width)a_y- the second coordinate of the matrix (height)a_value- the value to store- Returns:
- created or used memory cell
- Since:
- 3.2
-
readMatrixMemory
public java.lang.Object readMatrixMemory(int a_x, int a_y)Reads a value from the internal matrix memory.- Parameters:
a_x- the first coordinate of the matrix (width)a_y- the second coordinate of the matrix (height)- Returns:
- read value
- Since:
- 3.2
-
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
-
readFromMemoryIfExists
public java.lang.Object readFromMemoryIfExists(java.lang.String a_name)
- Parameters:
a_name- the name of the cell to evaluate- Returns:
- the value of a memory cell, if it exsists. Otherwise returns null.
- Since:
- 3.2
-
storeIndexedMemory
public CultureMemoryCell storeIndexedMemory(int a_index, java.lang.Object a_value)
Stores a value in the internal indexed memory.- Parameters:
a_index- index of the cella_value- the value to store- Returns:
- created or used memory cell
- Since:
- 3.2
-
readIndexedMemory
public java.lang.Object readIndexedMemory(int a_index)
Reads a value from the internal indexed memory.- Parameters:
a_index- index of the cell- Returns:
- read value (maybe null )
- Since:
- 3.2
-
clearMemory
public void clearMemory()
Clears the memory.- Since:
- 3.0
-
getGPFitnessFunction
public GPFitnessFunction getGPFitnessFunction()
-
setFitnessEvaluator
public void setFitnessEvaluator(IGPFitnessEvaluator a_fitnessEvaluator)
Set the fitness evaluator (deciding if a given fitness value is better when it's higher or better when it's lower).- Parameters:
a_fitnessEvaluator- the FitnessEvaluator to be used- Since:
- 3.3.3
-
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()
- Returns:
- true: throw an error during evolution in case a situation is detected where no function or terminal of a required type is declared in the GPConfiguration; false: don't throw an error but try a completely different combination of functions and terminals
-
setStrictProgramCreation
public void setStrictProgramCreation(boolean a_strict)
- Parameters:
a_strict- true: throw an error during evolution in case a situation is detected where no function or terminal of a required type is declared in the GPConfiguration; false: don't throw an error but try a completely different combination of functions and terminals
-
getProgramCreationMaxtries
public int getProgramCreationMaxtries()
-
setProgramCreationMaxTries
public void setProgramCreationMaxTries(int a_maxtries)
-
getGPFitnessEvaluator
public IGPFitnessEvaluator getGPFitnessEvaluator()
- Returns:
- the fitness evaluator set
- Since:
- 3.0
-
validateNode
public boolean validateNode(ProgramChromosome a_chrom, CommandGene a_node, CommandGene a_rootNode, int a_tries, int a_num, int a_recurseLevel, java.lang.Class a_type, CommandGene[] a_functionSet, int a_depth, boolean a_grow, int a_childIndex, boolean a_fullProgram)
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 valida_node- the node selected and to be validateda_rootNode- root node of the node to be validated (may be null)a_tries- number of times the validator has been called, useful for stopping by returning true if the number exceeds a limita_num- the chromosome's index in the individual of this chromosomea_recurseLevel- level of recursiona_type- the return type of the node neededa_functionSet- the array of available functionsa_depth- the needed depth of the program chromosomea_grow- true: use grow mode, false: use full modea_childIndex- index of the child in the parent node to which it belongs (-1 if node is root node)a_fullProgram- true: whole program is available in a_chrom- 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
-
equals
public boolean equals(java.lang.Object a_other)
Compares this entity against the specified object.- Overrides:
equalsin classConfiguration- Parameters:
a_other- the object to compare against- Returns:
- true: if the objects are the same, false otherwise
- Since:
- 3.1
-
compareTo
public int compareTo(java.lang.Object a_other)
Description copied from class:ConfigurationThe compareTo-method.- Specified by:
compareToin interfacejava.lang.Comparable- Overrides:
compareToin classConfiguration- Parameters:
a_other- the other object to compare- Returns:
- -1, 0, 1
-
isMaxNodeWarningPrinted
public boolean isMaxNodeWarningPrinted()
- Returns:
- see ProgramChromosome.growOrFull(...) and GPGenotype.evolve()
- Since:
- 3.2
-
flagMaxNodeWarningPrinted
public void flagMaxNodeWarningPrinted()
See ProgramChromosome.growOrFull(...) and GPGenotype.evolve().- Since:
- 3.2
-
setPrototypeProgram
public void setPrototypeProgram(IGPProgram a_program)
- Parameters:
a_program- IGPProgram- Since:
- 3.2
-
getPrototypeProgram
public IGPProgram getPrototypeProgram()
- Returns:
- prototype program set (maybe null if not setted previously)
- Since:
- 3.2
-
getMemorySize
public int getMemorySize()
- Returns:
- capacity of the memory in cells
- Since:
- 3.2
-
readProgramCache
public GPProgramInfo readProgramCache(GPProgram a_prog)
-
putToProgramCache
public GPProgramInfo putToProgramCache(GPProgram a_prog)
-
isUseProgramCache
public boolean isUseProgramCache()
-
setUseProgramCache
public void setUseProgramCache(boolean a_useCache)
-
putVariable
public void putVariable(Variable a_var)
Stores a Variable.- Parameters:
a_var- the Variable to store- Since:
- 3.2
-
getVariable
public Variable getVariable(java.lang.String a_varName)
- Parameters:
a_varName- name of variable to retriebe- Returns:
- Variable instance or null, if not found
- Since:
- 3.2
-
clone
public java.lang.Object clone()
- Specified by:
clonein interfaceICloneable- Overrides:
clonein classConfiguration- Returns:
- deep clone of this instance
- Since:
- 3.2
-
newInstanceGP
public GPConfiguration newInstanceGP(java.lang.String a_id, java.lang.String a_name)
Creates a new GPConfiguration instance by cloning. Allows to preset the ID and the name.- Parameters:
a_id- new ID for clonea_name- new name for clone- Returns:
- deep clone of this instance
- Since:
- 3.2
-
getJGAPFactory
public IJGAPFactory getJGAPFactory()
- Overrides:
getJGAPFactoryin classConfiguration- Returns:
- the JGAP factory registered
- Since:
- 3.2
-
setInitStrategy
public void setInitStrategy(IGPInitStrategy a_strategy)
- Parameters:
a_strategy- IGPInitStrategy- Since:
- 3.2.2
-
getInitStrategy
public IGPInitStrategy getInitStrategy()
- Returns:
- IGPInitStrategy
- Since:
- 3.2.2
-
setVerifyPrograms
public void setVerifyPrograms(boolean a_verify)
- Parameters:
a_verify- true: verify GP programs for correctness (i.e. is fitness computation possible without exception?)- Since:
- 3.3.4
-
isVerifyPrograms
public boolean isVerifyPrograms()
- Returns:
- true: verify GP programs for correctness (i.e. is fitness computation possible without exception?)
- Since:
- 3.3.4
-
setNoCommandGeneCloning
public void setNoCommandGeneCloning(boolean a_noCommandGeneCloning)
Decide whether to clone command genes when creating a new GP program in ProgramChromosome.- Parameters:
a_noCommandGeneCloning- boolean- Since:
- 3.4.3
-
isNoCommandGeneCloning
public boolean isNoCommandGeneCloning()
- Returns:
- true: do not clone command genes when creating a new GP program in ProgramChromosome
- Since:
- 3.4.3
-
-
DMelt 3.0 © DataMelt by jWork.ORG