📄 .#gpconfiguration.java.1.46
字号:
m_programCreationMaxTries = a_maxtries;
}
/**
* @return the fitness evaluator set
*
* @author Klaus Meffert
* @since 3.0
*/
public IGPFitnessEvaluator getGPFitnessEvaluator() {
return m_fitnessEvaluator;
}
/**
* 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.
*
* @param a_chrom the chromosome that will contain the node, if valid
* @param a_node the node selected and to be validated
* @param a_rootNode root node of the node to be validated (may be null)
* @param a_tries number of times the validator has been called, useful for
* stopping by returning true if the number exceeds a limit
* @param a_num the chromosome's index in the individual of this chromosome
* @param a_recurseLevel level of recursion
* @param a_type the return type of the node needed
* @param a_functionSet the array of available functions
* @param a_depth the needed depth of the program chromosome
* @param a_grow true: use grow mode, false: use full mode
* @param a_childIndex index of the child in the parent node to which it
* belongs (-1 if node is root node)
* @param a_fullProgram true: whole program is available in a_chrom
*
* @return true: node is valid; false: node is invalid
*
* @author Klaus Meffert
* @since 3.0
*/
public boolean validateNode(ProgramChromosome a_chrom, CommandGene a_node,
CommandGene a_rootNode, int a_tries, int a_num,
int a_recurseLevel, Class a_type,
CommandGene[] a_functionSet, int a_depth,
boolean a_grow, int a_childIndex,
boolean a_fullProgram) {
INodeValidator nodeValidator = getNodeValidator();
if (nodeValidator == null) {
return true;
}
return nodeValidator.validate(a_chrom, a_node, a_rootNode, a_tries, a_num,
a_recurseLevel, a_type, a_functionSet,
a_depth, a_grow, a_childIndex,
a_fullProgram);
}
/**
* Sets the node validator. Also see method validateNode.
*
* @param a_nodeValidator sic
*
* @author Klaus Meffert
* @since 3.0
*/
public void setNodeValidator(INodeValidator a_nodeValidator) {
m_nodeValidator = a_nodeValidator;
}
/**
* @return the node validator set
*
* @author Klaus Meffert
* @since 3.0
*/
public INodeValidator getNodeValidator() {
return m_nodeValidator;
}
/**
* Compares this entity against the specified object.
*
* @param a_other the object to compare against
* @return true: if the objects are the same, false otherwise
*
* @author Klaus Meffert
* @since 3.1
*/
public boolean equals(Object a_other) {
try {
return compareTo(a_other) == 0;
} catch (ClassCastException cex) {
return false;
}
}
public int compareTo(Object a_other) {
if (a_other == null) {
return 1;
}
else {
GPConfiguration other = (GPConfiguration) a_other;
return new CompareToBuilder().
append(m_objectiveFunction, other.m_objectiveFunction).
append(m_crossoverProb, other.m_crossoverProb).
append(m_reproductionProb, other.m_reproductionProb).
append(m_newChromsPercent, other.m_newChromsPercent).
append(m_maxCrossoverDepth, other.m_maxCrossoverDepth).
append(m_maxInitDepth, other.m_maxInitDepth).
append(m_selectionMethod.getClass(), other.m_selectionMethod.getClass()).
append(m_crossMethod.getClass(), other.m_crossMethod.getClass()).
append(m_programCreationMaxTries, other.m_programCreationMaxTries).
append(m_strictProgramCreation, other.m_strictProgramCreation).
append(m_fitnessEvaluator.getClass(),
other.m_fitnessEvaluator.getClass()).toComparison();
}
}
/**
*
* @return see ProgramChromosome.growOrFull(...) and GPGenotype.evolve()
*
* @author Klaus Meffert
* @since 3.2
*/
public boolean isMaxNodeWarningPrinted() {
return m_warningPrinted;
}
/**
* See ProgramChromosome.growOrFull(...) and GPGenotype.evolve().
*
* @author Klaus Meffert
* @since 3.2
*/
public void flagMaxNodeWarningPrinted() {
m_warningPrinted = true;
}
/**
*
* @param a_program IGPProgram
*
* @author Klaus Meffert
* @since 3.2
*/
public void setPrototypeProgram(IGPProgram a_program) {
m_prototypeProgram = a_program;
}
/**
* @return prototype program set (maybe null if not setted previously)
*
* @author Klaus Meffert
* @since 3.2
*/
public IGPProgram getPrototypeProgram() {
return m_prototypeProgram;
}
/**
* @return capacity of the memory in cells
*
* @author Klaus Meffert
* @since 3.2
*/
public int getMemorySize() {
return m_memory.size();
}
public GPProgramInfo readProgramCache(GPProgram a_prog) {
GPProgramInfo pci = new GPProgramInfo(a_prog, true);
pci.setFound(false);
return (GPProgramInfo) m_programCache.get(pci.getToStringNorm());
}
public GPProgramInfo putToProgramCache(GPProgram a_prog) {
GPProgramInfo pci = new GPProgramInfo(a_prog, true);
return (GPProgramInfo) m_programCache.put(pci.getToStringNorm(), pci);
}
public boolean isUseProgramCache() {
return m_useProgramCache;
}
public void setUseProgramCache(boolean a_useCache) {
m_useProgramCache = a_useCache;
}
/**
* Stores a Variable.
*
* @param a_var the Variable to store
*
* @author Klaus Meffert
* @since 3.2
*/
public void putVariable(Variable a_var) {
m_variables.put(a_var.getName(), a_var);
}
/**
* @param a_varName name of variable to retriebe
* @return Variable instance or null, if not found
*
* @author Klaus Meffert
* @since 3.2
*/
public Variable getVariable(String a_varName) {
return (Variable) m_variables.get(a_varName);
}
/**
* @return deep clone of this instance
*
* @author Klaus Meffert
* @since 3.2
*/
public Object clone() {
return newInstanceGP(getId(), getName());
}
/**
* Creates a new GPConfiguration instance by cloning. Allows to preset the
* ID and the name.
*
* @param a_id new ID for clone
* @param a_name new name for clone
* @return deep clone of this instance
*
* @author Klaus Meffert
* @since 3.2
*/
public GPConfiguration newInstanceGP(String a_id, String a_name) {
try {
GPConfiguration result = new GPConfiguration(getName());
// Clone JGAPFactory first because it helps in cloning other objects.
// ------------------------------------------------------------------
if (m_factory instanceof ICloneable) {
result.m_factory = (IJGAPFactory) ( (ICloneable) m_factory).clone();
}
else {
// We must fallback to a standardized solution.
// --------------------------------------------
m_factory = new JGAPFactory(false);
result.m_factory = (IJGAPFactory) ( (JGAPFactory) m_factory).clone();
}
if (result.m_factory == null) {
throw new IllegalStateException("JGAPFactory must not be null!");
}
if (m_objectiveFunction != null) {
result.m_objectiveFunction = m_objectiveFunction;
}
int popSize = getPopulationSize();
if (popSize > 0) {
result.setPopulationSize(popSize);
/*@todo move popSize from super to here!*/
}
result.m_crossoverProb = m_crossoverProb;
result.m_reproductionProb = m_reproductionProb;
result.m_newChromsPercent = m_newChromsPercent;
result.m_functionProb = m_functionProb;
result.m_maxCrossoverDepth = m_maxCrossoverDepth;
result.m_maxInitDepth = m_maxInitDepth;
result.m_minInitDepth = m_minInitDepth;
result.m_strictProgramCreation = m_strictProgramCreation;
result.m_programCreationMaxTries = m_programCreationMaxTries;
result.m_selectionMethod = (INaturalGPSelector) doClone(m_selectionMethod);
result.m_crossMethod = (CrossMethod) doClone(m_crossMethod);
result.m_fitnessEvaluator = (IGPFitnessEvaluator) doClone(
m_fitnessEvaluator);
result.m_nodeValidator = (INodeValidator) doClone(m_nodeValidator);
result.m_useProgramCache = m_useProgramCache;
result.m_verify = m_verify;
// Configurable data.
// ------------------
// result.m_config = new ConfigurationConfigurable();
// Identificative data.
// --------------------
result.setName(a_name);
result.setId(a_id);
result.makeThreadKey(); // Must be called after m_id is set
return result;
} catch (Throwable t) {
throw new CloneException(t);
}
}
/**
* @return the JGAP factory registered
*
* @author Klaus Meffert
* @since 3.2
*/
public IJGAPFactory getJGAPFactory() {
return m_factory;
}
/**
* When deserializing, do specific initializations.
*
* @param a_inputStream the ObjectInputStream provided for deserialzation
*
* @throws IOException
* @throws ClassNotFoundException
*
* @author Klaus Meffert
* @since 3.2
*/
private void readObject(ObjectInputStream a_inputStream)
throws IOException, ClassNotFoundException {
//always perform the default de-serialization first
a_inputStream.defaultReadObject();
try {
init(false);
} catch (InvalidConfigurationException iex) {
iex.printStackTrace();
throw new IOException(iex.toString());
}
}
/**
*
* @param a_strategy IGPInitStrategy
*
* @author Klaus Meffert
* @since 3.2.2
*/
public void setInitStrategy(IGPInitStrategy a_strategy) {
m_initStrategy = a_strategy;
}
/**
*
* @return IGPInitStrategy
*
* @author Klaus Meffert
* @since 3.2.2
*/
public IGPInitStrategy getInitStrategy() {
return m_initStrategy;
}
/**
* @param a_verify true: verify GP programs for correctness (i.e. is fitness
* computation possible without exception?)
*
* @author Klaus Meffert
* @since 3.3.4
*/
public void setVerifyPrograms(boolean a_verify) {
m_verify = a_verify;
}
/**
* @return true: verify GP programs for correctness (i.e. is fitness
* computation possible without exception?)
*
* @author Klaus Meffert
* @since 3.3.4
*/
public boolean isVerifyPrograms() {
return m_verify;
}
/**
* Decide whether to clone command genes when creating a new GP program in
* ProgramChromosome.
*
* @param a_noCommandGeneCloning boolean
*
* @author Klaus Meffert
* @since 3.4.3
*/
public void setNoCommandGeneCloning(boolean a_noCommandGeneCloning) {
m_noCommandGeneCloning = a_noCommandGeneCloning;
}
/**
* @return true: do not clone command genes when creating a new GP program in
* ProgramChromosome
*
* @author Klaus Meffert
* @since 3.4.3
*/
public boolean isNoCommandGeneCloning() {
return m_noCommandGeneCloning;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -