|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jgap.gp.BaseGPChromosome
org.jgap.gp.impl.ProgramChromosome
public class ProgramChromosome
Chromosome representing a single GP Program.
| Constructor Summary | |
|---|---|
ProgramChromosome()
Default constructor. |
|
ProgramChromosome(GPConfiguration a_conf)
|
|
ProgramChromosome(GPConfiguration a_conf,
CommandGene[] a_initialGenes)
|
|
ProgramChromosome(GPConfiguration a_conf,
int a_size)
|
|
ProgramChromosome(GPConfiguration a_conf,
int a_size,
CommandGene[] a_functionSet,
java.lang.Class[] a_argTypes,
IGPProgram a_ind)
|
|
ProgramChromosome(GPConfiguration a_conf,
int a_size,
IGPProgram a_ind)
|
|
| Method Summary | |
|---|---|
void |
cleanup()
Clean up the chromosome. |
java.lang.Object |
clone()
|
int |
compareTo(java.lang.Object a_other)
Compares the given chromosome to this chromosome. |
boolean |
contains(CommandGene[] a_functionSet,
java.lang.Class a_function)
Checks if a function or terminal of the class of the given instance exists within a_functionSet |
boolean |
contains(CommandGene[] a_functionSet,
CommandGene a_function)
Checks if a function or terminal of the class of the given instance exists within a_functionSet |
int |
contains(CommandGene[] a_functionSet,
CommandGene a_function,
int a_limit)
Checks if a function or terminal of the class of the given instance exists within a_functionSet at least a_limit times |
protected CommandGene |
createGene(java.lang.String a_geneClassName,
java.lang.String a_persistentRepresentation)
Creates a new instance of gene. |
protected java.lang.String |
decode(java.lang.String a_string)
|
protected java.lang.String |
encode(java.lang.String a_string)
|
boolean |
equals(java.lang.Object a_other)
Compares this chromosome against the specified object. |
boolean |
execute_boolean(int n,
int child,
java.lang.Object[] args)
Executes this node as a boolean. |
boolean |
execute_boolean(java.lang.Object[] args)
Executes this node as a boolean. |
double |
execute_double(int n,
int child,
java.lang.Object[] args)
|
double |
execute_double(java.lang.Object[] args)
Executes this node as a double. |
float |
execute_float(int n,
int child,
java.lang.Object[] args)
|
float |
execute_float(java.lang.Object[] args)
Executes this node as a float. |
int |
execute_int(int n,
int child,
java.lang.Object[] args)
|
int |
execute_int(java.lang.Object[] args)
Executes this node as an integer. |
long |
execute_long(int n,
int child,
java.lang.Object[] args)
|
long |
execute_long(java.lang.Object[] args)
Executes this node as a long. |
java.lang.Object |
execute_object(int n,
int child,
java.lang.Object[] args)
|
java.lang.Object |
execute_object(java.lang.Object[] args)
Executes this node as an object. |
void |
execute_void(int n,
int child,
java.lang.Object[] args)
|
void |
execute_void(java.lang.Object[] args)
Executes this node, returning nothing. |
java.lang.Object |
execute(int n,
int child,
java.lang.Object[] args)
|
java.lang.Object |
execute(java.lang.Object[] args)
Executes this node without knowing its return type. |
java.lang.Object |
getApplicationData()
Retrieves the application-specific data that is attached to this Chromosome. |
java.lang.Class[] |
getArgTypes()
|
int |
getArity()
|
java.lang.String |
getBusinessKey()
|
int |
getChild(CommandGene a_node,
int a_child)
|
int |
getChild(int a_index,
int a_child)
Gets the a_child'th child of the a_index'th node in this chromosome. |
int |
getDepth(int a_index)
Gets the depth of the branch starting at the a_index'th node. |
CommandGene[] |
getFunctions()
|
CommandGene[] |
getFunctionSet()
|
CommandGene |
getGene(int a_locus)
Returns the Gene at the given index (locus) within the Chromosome. |
CommandGene |
getNode(java.lang.Class a_type,
boolean a_exactMatch)
Checks whether a node with a given type is contained in the program. |
CommandGene |
getNode(java.lang.Class a_type,
boolean a_exactMatch,
int a_startIndex)
|
int |
getParentNode(int a_child)
Gets the node which is the parent of the given node in this chromosome. |
java.lang.String |
getPersistentRepresentation()
|
int |
getSize(int a_index)
Gets the number of nodes in the branch starting at the a_index'th node. |
void |
growOrFull(int a_num,
int a_depth,
java.lang.Class a_type,
java.lang.Class[] a_argTypes,
CommandGene[] a_functionSet,
boolean a_grow,
int a_tries)
Initialize this chromosome using the grow or the full method. |
protected CommandGene[] |
growOrFullNode(int a_num,
int a_depth,
java.lang.Class a_returnType,
int a_subReturnType,
CommandGene[] a_functionSet,
CommandGene a_rootNode,
int a_recurseLevel,
boolean a_grow,
int a_childNum,
boolean a_validateNode)
Create a tree of nodes using the grow or the full method. |
boolean |
isCompareApplicationData()
|
boolean |
isPossible(java.lang.Class a_returnType,
int a_subReturnType,
CommandGene[] a_nodeSet,
boolean a_function,
boolean a_growing)
Determines whether there exists a function or terminal in the given node set with the given return and sub return type. |
void |
redepth()
Recalculate the depth of each node. |
protected int |
redepth(int a_index)
Calculate the depth of the next node and the indices of the children of the current node. |
protected CommandGene |
selectNode(int a_chromIndex,
java.lang.Class a_returnType,
int a_subReturnType,
CommandGene[] a_functionSet,
boolean a_function,
boolean a_growing)
Randomly chooses a valid node from the functions set. |
void |
setArgTypes(java.lang.Class[] a_argTypes)
|
void |
setCompareApplicationData(boolean a_doCompare)
Should we also consider the application data when comparing? |
void |
setFunctions(CommandGene[] a_functions)
|
void |
setFunctionSet(CommandGene[] a_functionSet)
|
void |
setGene(int index,
CommandGene a_gene)
|
void |
setValueFromPersistentRepresentation(java.lang.String a_representation)
|
int |
size()
|
protected static java.util.List |
split(java.lang.String a_string)
Splits a_string into individual gene representations. |
java.lang.String |
toString(int a_startNode)
Output program in left-hand notion (e.g.: "+ X Y" for "X + Y"). |
java.lang.String |
toStringDebug()
|
java.lang.String |
toStringNorm(int a_startNode)
Output program in "natural" notion (e.g.: "X + Y" for "X + Y"). |
| Methods inherited from class org.jgap.gp.BaseGPChromosome |
|---|
getAssignableFromClass, getCommandOfClass, getFunction, getFunction, getGPConfiguration, getIndividual, getNode, getTerminal, getTerminal, getVariableWithReturnType, numFunctions, numFunctions, numTerminals, numTerminals, setIndividual |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ProgramChromosome(GPConfiguration a_conf,
int a_size)
throws InvalidConfigurationException
InvalidConfigurationException
public ProgramChromosome(GPConfiguration a_conf,
int a_size,
IGPProgram a_ind)
throws InvalidConfigurationException
InvalidConfigurationException
public ProgramChromosome(GPConfiguration a_conf,
int a_size,
CommandGene[] a_functionSet,
java.lang.Class[] a_argTypes,
IGPProgram a_ind)
throws InvalidConfigurationException
InvalidConfigurationException
public ProgramChromosome(GPConfiguration a_conf,
CommandGene[] a_initialGenes)
throws InvalidConfigurationException
InvalidConfigurationException
public ProgramChromosome(GPConfiguration a_conf)
throws InvalidConfigurationException
InvalidConfigurationException
public ProgramChromosome()
throws InvalidConfigurationException
InvalidConfigurationException| Method Detail |
|---|
public void setArgTypes(java.lang.Class[] a_argTypes)
public java.lang.Object clone()
clone in class java.lang.Objectpublic void cleanup()
cleanup in interface IGPChromosome
public void growOrFull(int a_num,
int a_depth,
java.lang.Class a_type,
java.lang.Class[] a_argTypes,
CommandGene[] a_functionSet,
boolean a_grow,
int a_tries)
a_num - the chromosome's index in the individual of this chromosomea_depth - the maximum depth of the chromosome to createa_type - the type of the chromosome to createa_argTypes - the array of argument types for this chromosomea_functionSet - the set of nodes valid to pick froma_grow - true: use grow method; false: use full methoda_tries - maximum number of tries for creating a valid programpublic java.lang.String toString(int a_startNode)
a_startNode - node to start with
public java.lang.String toStringNorm(int a_startNode)
toStringNorm in interface IGPChromosomea_startNode - the node to start with, e.g. 0 for a complete dump of
the program
public java.lang.String getBusinessKey()
getBusinessKey in interface IBusinessKeypublic java.lang.String toStringDebug()
public boolean isPossible(java.lang.Class a_returnType,
int a_subReturnType,
CommandGene[] a_nodeSet,
boolean a_function,
boolean a_growing)
a_returnType - the return type to look fora_subReturnType - the sub return type to look fora_nodeSet - the array of nodes to look througha_function - true to look for a function, false to look for a terminala_growing - true: grow mode, false: full mode
protected CommandGene selectNode(int a_chromIndex,
java.lang.Class a_returnType,
int a_subReturnType,
CommandGene[] a_functionSet,
boolean a_function,
boolean a_growing)
a_chromIndex - index of the chromosome in the individual (0..n-1)a_returnType - the return type of node to choosea_subReturnType - the sub return type to look fora_functionSet - the functions to usea_function - true to choose a function, false to choose a terminala_growing - true to ignore the function parameter, false otherwise
protected CommandGene[] growOrFullNode(int a_num,
int a_depth,
java.lang.Class a_returnType,
int a_subReturnType,
CommandGene[] a_functionSet,
CommandGene a_rootNode,
int a_recurseLevel,
boolean a_grow,
int a_childNum,
boolean a_validateNode)
a_num - the chromosome's index in the individual of this chromosomea_depth - the maximum depth of the tree to createa_returnType - the return type the lastly evaluated node must havea_subReturnType - the sub return type to look fora_functionSet - the set of function valid to pick froma_rootNode - null, or parent node of the node to developa_recurseLevel - 0 for first calla_grow - true: use grow method; false: use full methoda_childNum - index of the child in the parent node to which it belongs
(-1 if node is root node)a_validateNode - true: check if node selected is valid (when called
recursively a_validateNode is set to true)
public void redepth()
redepth in interface IGPChromosomeprotected int redepth(int a_index)
a_index - the index of the reference depth
public int getChild(int a_index,
int a_child)
getChild in interface IGPChromosomea_index - the node number of the parenta_child - the child number (starting from 0) of the parent
public int getChild(CommandGene a_node,
int a_child)
public CommandGene[] getFunctionSet()
getFunctionSet in interface IGPChromosomepublic void setFunctionSet(CommandGene[] a_functionSet)
public CommandGene[] getFunctions()
getFunctions in interface IGPChromosome
public void setFunctions(CommandGene[] a_functions)
throws InvalidConfigurationException
InvalidConfigurationExceptionpublic int getSize(int a_index)
a_index - the index of the node at which to start counting
public int getDepth(int a_index)
a_index - the index of the node at which to check the depth
public int getParentNode(int a_child)
a_child - the child node
public CommandGene getNode(java.lang.Class a_type,
boolean a_exactMatch)
a_type - the type to look fora_exactMatch - true: look for exactly the given type: false: also look
for sub types
public CommandGene getNode(java.lang.Class a_type,
boolean a_exactMatch,
int a_startIndex)
public boolean execute_boolean(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not
boolean
public boolean execute_boolean(int n,
int child,
java.lang.Object[] args)
n - the index of the parent nodechild - the child number of the node to executeargs - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not
booleanpublic void execute_void(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not void
public void execute_void(int n,
int child,
java.lang.Object[] args)
public int execute_int(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not
integer
public int execute_int(int n,
int child,
java.lang.Object[] args)
public long execute_long(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not long
public long execute_long(int n,
int child,
java.lang.Object[] args)
public float execute_float(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not float
public float execute_float(int n,
int child,
java.lang.Object[] args)
public double execute_double(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if this node's type is not double
public double execute_double(int n,
int child,
java.lang.Object[] args)
public java.lang.Object execute_object(java.lang.Object[] args)
args - the arguments for execution
java.lang.UnsupportedOperationException - if the type of this node is not
of type Object
public java.lang.Object execute_object(int n,
int child,
java.lang.Object[] args)
public java.lang.Object execute(java.lang.Object[] args)
args - the arguments for execution
public java.lang.Object execute(int n,
int child,
java.lang.Object[] args)
public void setGene(int index,
CommandGene a_gene)
public java.lang.Class[] getArgTypes()
public int getArity()
public int size()
public int compareTo(java.lang.Object a_other)
compareTo in interface java.lang.Comparablea_other - the chromosome against which to compare this chromosome
public boolean equals(java.lang.Object a_other)
equals in class java.lang.Objecta_other - the object to compare against
public void setCompareApplicationData(boolean a_doCompare)
a_doCompare - true: consider application data in method compareTopublic boolean isCompareApplicationData()
public java.lang.Object getApplicationData()
public CommandGene getGene(int a_locus)
a_locus - index of the gene value to be returned
protected java.lang.String encode(java.lang.String a_string)
protected java.lang.String decode(java.lang.String a_string)
public java.lang.String getPersistentRepresentation()
getPersistentRepresentation in interface IGPChromosome
public void setValueFromPersistentRepresentation(java.lang.String a_representation)
throws UnsupportedRepresentationException
a_representation - String
UnsupportedRepresentationException
protected CommandGene createGene(java.lang.String a_geneClassName,
java.lang.String a_persistentRepresentation)
throws java.lang.Exception
a_geneClassName - name of the gene classa_persistentRepresentation - persistent representation of the gene to
create (could be obtained via getPersistentRepresentation)
java.lang.Exception
protected static final java.util.List split(java.lang.String a_string)
throws UnsupportedRepresentationException
a_string - the string to split
UnsupportedRepresentationException
public boolean contains(CommandGene[] a_functionSet,
CommandGene a_function)
a_functionSet - the set of functions to checka_function - the commandgene to check for via its class
public boolean contains(CommandGene[] a_functionSet,
java.lang.Class a_function)
a_functionSet - the set of functions to checka_function - the commandgene to check for via its class
public int contains(CommandGene[] a_functionSet,
CommandGene a_function,
int a_limit)
a_functionSet - the set of functions to checka_function - the commandgene to check for via its classa_limit - if a_limit occurrences of a_function were detected, exit
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||