📄 .#gpconfiguration.java.1.46
字号:
*
* @author Klaus Meffert
* @since 3.4
*/
public void setDynamizeArityProb(float a_dynArityProb) {
m_dynArityProb = a_dynArityProb;
}
/**
* @param a_functionProb probability that a function instead of a terminal
* is chosen in crossing over (between 0 and 1)
*
* @author Klaus Meffert
* @since 3.2
*/
public void setFunctionProb(double a_functionProb) {
m_functionProb = a_functionProb;
}
/**
* @return probability that a function instead of a terminal is chosen in
* crossing over
*
* @author Klaus Meffert
* @since 3.2
*/
public double getFunctionProb() {
return m_functionProb;
}
public void setNewChromsPercent(double a_newChromsPercent) {
if (m_newChromsPercent >= 1.0d) {
throw new IllegalArgumentException(
"Parameter value must be smaller than 1!");
}
m_newChromsPercent = a_newChromsPercent;
}
public double getNewChromsPercent() {
return m_newChromsPercent;
}
public int getMaxCrossoverDepth() {
return m_maxCrossoverDepth;
}
public void setMaxCrossoverDepth(int a_maxCrossoverDepth) {
m_maxCrossoverDepth = a_maxCrossoverDepth;
}
public INaturalGPSelector getSelectionMethod() {
return m_selectionMethod;
}
public CrossMethod getCrossMethod() {
return m_crossMethod;
}
public int getMaxInitDepth() {
return m_maxInitDepth;
}
public void setMaxInitDepth(int a_maxDepth) {
m_maxInitDepth = a_maxDepth;
}
public int getMinInitDepth() {
return m_minInitDepth;
}
public void setMinInitDepth(int a_minDepth) {
m_minInitDepth = a_minDepth;
}
public void pushToStack(Object a_value) {
m_stack.push(a_value);
}
public Object popFromStack() {
return m_stack.pop();
}
public Object peekStack() {
return m_stack.peek();
}
public int stackSize() {
return m_stack.size();
}
public void clearStack() {
m_stack.clear();
}
/**
* Stores a value in the internal memory.
*
* @param a_name named index of the memory cell
* @param a_value the value to store
*
* @author Klaus Meffert
* @since 3.0
*/
public void storeInMemory(String a_name, Object a_value) {
m_memory.set(a_name, a_value, -1);
}
/**
* Creates an instance of a matrix with a unique name.
*
* @param a_name the name of the matrix
* @param a_cols number of columns the matrix should have
* @param a_rows number of rows the matrix should have
*
* @author Klaus Meffert
* @since 3.4.3
*/
public void createMatrix(String a_name, int a_cols, int a_rows) {
if (a_name == null || a_name.length() < 1) {
throw new IllegalArgumentException("Matrix name must not be empty!");
}
if (a_cols < 1 || a_rows < 1) {
throw new IllegalArgumentException(
"Number of colums and rows must be greater than zero!");
}
char[][] m_matrix = new char[a_cols][a_rows];
m_matrices.put(a_name, m_matrix);
}
/**
* Sets a matrix field with a value.
*
* @param a_name the name of the matrix
* @param a_col column in the matrix
* @param a_row row in the matrix
* @param a_value the value to set in the matrix at given column and row
*
* @author Klaus Meffert
* @since 3.4.3
*/
public void setMatrix(String a_name, int a_col, int a_row, char a_value) {
char[][] m_matrix = m_matrices.get(a_name);
if (m_matrix == null) {
throw new IllegalArgumentException("Matrix with name " + a_name +
" not found!");
}
m_matrix[a_col][a_row] = a_value;
}
/**
* Resets the matrix by filling it with a given character.
*
* @param a_name the name of the matrix
* @param a_filler the character to fill the whole matrix with
*
* @author Klaus Meffert
* @since 3.4.3
*/
public void resetMatrix(String a_name, char a_filler) {
char[][] m_matrix = m_matrices.get(a_name);
if (m_matrix == null) {
throw new IllegalArgumentException("Matrix with name " + a_name +
" not found!");
}
for (int col = 0; col < m_matrix.length; col++) {
for (int row = 0; row < m_matrix[col].length; row++) {
m_matrix[col][row] = a_filler;
}
}
}
/**
* Reads a matrix cell and returns the value.
*
* @param a_name the name of the matrix
* @param a_col the column to read
* @param a_row the row to read
* @return the value in the matrix
*
* @author Klaus Meffert
* @since 3.4.3
*/
public char readMatrix(String a_name, int a_col, int a_row) {
char[][] m_matrix = m_matrices.get(a_name);
if (m_matrix == null) {
throw new IllegalArgumentException("Matrix with name " + a_name +
" not found!");
}
return m_matrix[a_col][a_row];
}
/**
* Retrieves a named matrix.
*
* @param a_name the name of the matrix
* @return the matrix itself
*
* @author Klaus Meffert
* @since 3.4.3
*/
public char[][] getMatrix(String a_name) {
char[][] m_matrix = m_matrices.get(a_name);
return m_matrix;
}
/**
* Stores a value in the internal matrix memory.
*
* @param a_x the first coordinate of the matrix (width)
* @param a_y the second coordinate of the matrix (height)
* @param a_value the value to store
* @return created or used memory cell
*
* @author Klaus Meffert
* @since 3.2
*/
public CultureMemoryCell storeMatrixMemory(int a_x, int a_y, Object a_value) {
return m_memory.setMatrix(a_x, a_y, a_value);
}
/**
* Reads a value from the internal matrix memory.
*
* @param a_x the first coordinate of the matrix (width)
* @param a_y the second coordinate of the matrix (height)
* @return read value
*
* @author Klaus Meffert
* @since 3.2
*/
public Object readMatrixMemory(int a_x, int a_y) {
return m_memory.getMatrix(a_x, a_y).getCurrentValue();
}
/**
* Reads a value from the internal memory.
*
* @param a_name named index of the memory cell to read out
* @return read value
*
* @author Klaus Meffert
* @since 3.0
*/
public Object readFromMemory(String a_name) {
return m_memory.get(a_name).getCurrentValue();
}
/**
* @param a_name the name of the cell to evaluate
* @return the value of a memory cell, if it exsists. Otherwise returns null.
*
* @author Klaus Meffert
* @since 3.2
*/
public Object readFromMemoryIfExists(String a_name) {
CultureMemoryCell cell = null;
try {
cell = m_memory.get(a_name);
} catch (IllegalArgumentException iex) {
// Memory name not found: OK.
// --------------------------
;
}
if (cell == null) {
return null;
}
return cell.getCurrentValue();
}
/**
* Stores a value in the internal indexed memory.
*
* @param a_index index of the cell
* @param a_value the value to store
* @return created or used memory cell
*
* @author Klaus Meffert
* @since 3.2
*/
public CultureMemoryCell storeIndexedMemory(int a_index, Object a_value) {
return m_memory.set(a_index, a_value, -1, "noname");
}
/**
* Reads a value from the internal indexed memory.
*
* @param a_index index of the cell
* @return read value (maybe null )
*
* @author Klaus Meffert
* @since 3.2
*/
public Object readIndexedMemory(int a_index) {
CultureMemoryCell cell = m_memory.get(a_index);
if (cell == null) {
return null;
}
else {
return cell.getCurrentValue();
}
}
/**
* Clears the memory.
*
* @author Klaus Meffert
* @since 3.0
*/
public void clearMemory() {
m_memory.clear();
}
public GPFitnessFunction getGPFitnessFunction() {
return m_objectiveFunction;
}
/**
* Set the fitness evaluator (deciding if a given fitness value is better
* when it's higher or better when it's lower).
* @param a_fitnessEvaluator the FitnessEvaluator to be used
*
* @author Klaus Meffert
* @since 3.3.3
*/
public void setFitnessEvaluator(IGPFitnessEvaluator a_fitnessEvaluator) {
setGPFitnessEvaluator(a_fitnessEvaluator);
}
/**
* 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.
*
* @param a_functionToSet fitness function to be used
*
* @throws InvalidConfigurationException if the fitness function is null, or
* if this Configuration object is locked.
*
* @author Klaus Meffert
* @since 1.1
*/
public synchronized void setFitnessFunction(GPFitnessFunction a_functionToSet)
throws InvalidConfigurationException {
verifyChangesAllowed();
// Sanity check: Make sure that the given fitness function isn't null.
// -------------------------------------------------------------------
if (a_functionToSet == null) {
throw new InvalidConfigurationException(
"The FitnessFunction instance must not be null.");
}
// Ensure that no other fitness function has been set in a different
// configuration object within the same thread!
// -----------------------------------------------------------------
checkProperty(PROPERTY_FITFUNC_INST, a_functionToSet, m_objectiveFunction,
"Fitness function has already been set differently.");
m_objectiveFunction = a_functionToSet;
}
/**
* @return 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
*
* @author Klaus Meffert
*/
public boolean isStrictProgramCreation() {
return m_strictProgramCreation;
}
/**
* @param 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
*
* @author Klaus Meffert
*/
public void setStrictProgramCreation(boolean a_strict) {
m_strictProgramCreation = a_strict;
}
public int getProgramCreationMaxtries() {
return m_programCreationMaxTries;
}
public void setProgramCreationMaxTries(int a_maxtries) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -