|
JGAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jgap.gp.CommandGene
public abstract class CommandGene
Abstract base class for all GP commands. A CommandGene represents a node within a GP program. A node either is a terminal (like a constant), or a function (having input parameters). A CommandGene can hold additional CommandGene's, it acts sort of like a * Composite (also see CompositeGene for a comparable concept, although for a GA).
Nested Class Summary | |
---|---|
static class |
CommandGene.COMMAND_TYPE
|
Field Summary | |
---|---|
static java.lang.Class |
BooleanClass
|
static java.lang.Class |
CharacterClass
|
static double |
DELTA
Delta, useful for comparing doubles and floats. |
static java.lang.Class |
DoubleClass
|
static java.lang.Class |
FloatClass
|
static java.lang.Class |
IntegerClass
|
static java.lang.Class |
LongClass
|
int |
nodeIndex
|
static java.lang.Class |
VoidClass
|
Constructor Summary | |
---|---|
CommandGene()
Default constructor, only for dynamic instantiation. |
|
CommandGene(GPConfiguration a_conf,
int a_arity,
java.lang.Class a_returnType)
|
|
CommandGene(GPConfiguration a_conf,
int a_arity,
java.lang.Class a_returnType,
int a_subReturnType)
Allows specifying a sub return type. |
|
CommandGene(GPConfiguration a_conf,
int a_arity,
java.lang.Class a_returnType,
int a_subReturnType,
int a_childSubType)
Command with one child: Allows specifying a sub return type and a sub child type. |
|
CommandGene(GPConfiguration a_conf,
int a_arity,
java.lang.Class a_returnType,
int a_subReturnType,
int[] a_childSubTypes)
Allows specifying a sub return type and sub child types. |
Method Summary | |
---|---|
protected void |
check(ProgramChromosome a_program)
|
protected void |
check(ProgramChromosome a_program,
int a_index)
|
void |
cleanup()
|
int |
compareTo(java.lang.Object a_other)
The compareTo-method. |
void |
dynamizeArity()
Adaptation of the arity so that it represents a value within the interval [m_arityMin, m_arityMax]. |
void |
ensureUniqueness(ProgramChromosome a_program)
Ensures that the calling command is unique within the program. |
void |
ensureUniqueness(ProgramChromosome a_program,
int a_maxCount)
Ensures that the calling command is unique within the program. |
boolean |
ensureUniqueness2(ProgramChromosome a_program,
int a_maxCount)
Ensures that the calling command is unique within the program. |
boolean |
equals(java.lang.Object a_other)
The equals-method. |
boolean |
execute_boolean(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node as a boolean. |
double |
execute_double(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node as a double. |
float |
execute_float(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node as a float. |
int |
execute_int(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node as an integer. |
long |
execute_long(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node as a long. |
java.lang.Object |
execute_object(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node as an object. |
void |
execute_void(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node, returning nothing. |
java.lang.Object |
execute(ProgramChromosome c,
int n,
java.lang.Object[] args)
Executes this node without knowing its return type. |
java.lang.Object |
getAllele()
|
java.lang.Object |
getApplicationData()
Retrieves the application-specific data that is attached to this Gene. |
int |
getArity(IGPProgram a_indvividual)
Arity of the command. |
protected int |
getArityMax()
|
protected int |
getArityMin()
|
java.lang.Class |
getChildType(IGPProgram a_ind,
int a_chromNum)
Gets the type of node allowed from the given child number. |
protected CommandGene.COMMAND_TYPE |
getCommandType()
The type of the command this gene represents. |
double |
getEnergy()
|
GPConfiguration |
getGPConfiguration()
|
protected java.lang.Object |
getInternalValue()
|
java.lang.String |
getName()
|
java.lang.String |
getPersistentRepresentation()
|
protected java.lang.String |
getPersistentRepresentationExt()
Override in your sub classes of CommandGene if you have to add additional information to be persisted. |
java.lang.Class |
getReturnType()
|
int |
getSubChildType(int a_childNum)
|
int[] |
getSubChildTypes()
|
int |
getSubReturnType()
|
int |
hashCode()
Retrieves the hash code value for a CommandGene. |
protected void |
init()
Initializations, called from each Constructor. |
boolean |
isAffectGlobalState()
|
boolean |
isCompareApplicationData()
|
boolean |
isFloatType()
|
boolean |
isIntegerType()
|
boolean |
isValid(ProgramChromosome a_program)
Subclasses capable of validating programs should overwrite this method. |
boolean |
isValid(ProgramChromosome a_program,
int a_index)
|
void |
setAllele(java.lang.Object a_newValue)
|
void |
setApplicationData(java.lang.Object a_newData)
This sets the application-specific data that is attached to this Gene. |
protected void |
setArity(int a_arity)
Should only be used by class CommandDynamicArity or a similar class. |
protected void |
setArityMax(int a_arityMax)
Should only be used by class CommandDynamicArity or a similar class. |
protected void |
setArityMin(int a_arityMin)
Should only be used by class CommandDynamicArity or a similar class. |
void |
setCompareApplicationData(boolean a_doCompare)
Should we also consider the application data when comparing? |
void |
setEnergy(double a_energy)
Sets the energy of the gene. |
void |
setNoValidation(boolean a_noValidation)
|
void |
setReturnType(java.lang.Class a_type)
Sets the return type of this node. |
void |
setToRandomValue(RandomGenerator a_numberGenerator)
|
void |
setValueFromPersistentRepresentation(java.lang.String a_representation)
|
protected void |
setValueFromString(int a_index,
java.lang.String a_value)
Override in your sub classes of CommandGene if you have to add additional information to be persisted. |
int |
size()
|
abstract java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final double DELTA
public static final java.lang.Class BooleanClass
public static final java.lang.Class IntegerClass
public static final java.lang.Class LongClass
public static final java.lang.Class FloatClass
public static final java.lang.Class DoubleClass
public static final java.lang.Class VoidClass
public static final java.lang.Class CharacterClass
public int nodeIndex
Constructor Detail |
---|
public CommandGene() throws java.lang.Exception
java.lang.Exception
public CommandGene(GPConfiguration a_conf, int a_arity, java.lang.Class a_returnType) throws InvalidConfigurationException
a_conf
- the configuration to usea_arity
- the number of children of the nodea_returnType
- type of the return value of the node
InvalidConfigurationException
public CommandGene(GPConfiguration a_conf, int a_arity, java.lang.Class a_returnType, int a_subReturnType, int[] a_childSubTypes) throws InvalidConfigurationException
a_conf
- the configuration to usea_arity
- the number of children of the nodea_returnType
- type of the return value of the nodea_subReturnType
- sub type of the return type, optional usagea_childSubTypes
- sub types of the childs, optional usage
InvalidConfigurationException
public CommandGene(GPConfiguration a_conf, int a_arity, java.lang.Class a_returnType, int a_subReturnType) throws InvalidConfigurationException
a_conf
- the configuration to usea_arity
- the number of children of the nodea_returnType
- type of the return value of the nodea_subReturnType
- sub type of the return type, optional usage
InvalidConfigurationException
public CommandGene(GPConfiguration a_conf, int a_arity, java.lang.Class a_returnType, int a_subReturnType, int a_childSubType) throws InvalidConfigurationException
a_conf
- the configuration to usea_arity
- the number of children of the nodea_returnType
- type of the return value of the nodea_subReturnType
- sub type of the return type, optional usagea_childSubType
- sub type of a child, optional usage
InvalidConfigurationException
Method Detail |
---|
protected void init()
public void setAllele(java.lang.Object a_newValue)
public java.lang.Object getAllele()
public void setToRandomValue(RandomGenerator a_numberGenerator)
public void cleanup()
public int size()
public int getArity(IGPProgram a_indvividual)
a_indvividual
- the invididual the command's arity may depend on (in
most cases the arity will not depend on the individual)
protected void setArity(int a_arity)
a_arity
- the arity to set, overrides the current arity.public void dynamizeArity()
protected void setArityMin(int a_arityMin)
a_arityMin
- the minimal arity possibleprotected void setArityMax(int a_arityMax)
a_arityMax
- the maximal arity possibleprotected int getArityMin()
protected int getArityMax()
public int compareTo(java.lang.Object a_other)
compareTo
in interface java.lang.Comparable
a_other
- the other object to compare
public boolean equals(java.lang.Object a_other)
equals
in class java.lang.Object
a_other
- the other object to compare
public abstract java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object execute(ProgramChromosome c, int n, java.lang.Object[] args)
c
- the current Chromosome which is executingn
- the index of the Function in the Chromosome's Function array which
is executingargs
- the arguments to the current Chromosome which is executing
java.lang.UnsupportedOperationException
- if the type of this node is not
booleanpublic java.lang.Class getReturnType()
public void setReturnType(java.lang.Class a_type)
a_type
- the type to set the return type topublic boolean execute_boolean(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public void execute_void(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public int execute_int(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public long execute_long(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public float execute_float(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public double execute_double(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public java.lang.Object execute_object(ProgramChromosome c, int n, java.lang.Object[] args)
c
- ignored heren
- ignored hereargs
- ignored here
java.lang.UnsupportedOperationException
public java.lang.String getName()
public java.lang.Class getChildType(IGPProgram a_ind, int a_chromNum)
a_ind
- the individual the child belongs toa_chromNum
- the chromosome number
protected java.lang.Object getInternalValue()
public int hashCode()
hashCode
in class java.lang.Object
public boolean isIntegerType()
public boolean isFloatType()
public boolean isAffectGlobalState()
public boolean isValid(ProgramChromosome a_program)
a_program
- the ProgramChromosome to validate
public boolean isValid(ProgramChromosome a_program, int a_index)
protected void check(ProgramChromosome a_program)
protected void check(ProgramChromosome a_program, int a_index)
public void setNoValidation(boolean a_noValidation)
public GPConfiguration getGPConfiguration()
public void setApplicationData(java.lang.Object a_newData)
a_newData
- the new application-specific data to attach to this
Genepublic java.lang.Object getApplicationData()
public void setCompareApplicationData(boolean a_doCompare)
a_doCompare
- true: consider application data in method compareTo
and equalspublic boolean isCompareApplicationData()
public double getEnergy()
public void setEnergy(double a_energy)
a_energy
- the energy to setpublic int getSubReturnType()
public int getSubChildType(int a_childNum)
a_childNum
- the index of the child
public int[] getSubChildTypes()
public void ensureUniqueness(ProgramChromosome a_program)
a_program
- the program to validatepublic void ensureUniqueness(ProgramChromosome a_program, int a_maxCount)
a_program
- the program to validatea_maxCount
- maximum number of allowed occurencespublic boolean ensureUniqueness2(ProgramChromosome a_program, int a_maxCount)
a_program
- the program to validatea_maxCount
- maximum number of allowed occurences
protected CommandGene.COMMAND_TYPE getCommandType()
public java.lang.String getPersistentRepresentation()
protected java.lang.String getPersistentRepresentationExt()
public void setValueFromPersistentRepresentation(java.lang.String a_representation) throws UnsupportedRepresentationException
a_representation
- String
UnsupportedRepresentationException
protected void setValueFromString(int a_index, java.lang.String a_value)
a_index
- index of the parameter in the range 0..n-1 (n=number of
parameters)a_value
- string value of the parameter
|
JGAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |