JGAP

org.jgap.gp.terminal
Class Terminal

java.lang.Object
  extended by org.jgap.gp.CommandGene
      extended by org.jgap.gp.terminal.Terminal
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, IMutateable, ICloneable

public class Terminal
extends CommandGene
implements IMutateable, ICloneable

A terminal is a static number that can be mutated.

Since:
3.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jgap.gp.CommandGene
CommandGene.COMMAND_TYPE
 
Field Summary
 
Fields inherited from class org.jgap.gp.CommandGene
BooleanClass, CharacterClass, DELTA, DoubleClass, FloatClass, IntegerClass, LongClass, nodeIndex, VoidClass
 
Constructor Summary
Terminal()
           
Terminal(GPConfiguration a_conf, java.lang.Class a_returnType)
           
Terminal(GPConfiguration a_conf, java.lang.Class a_returnType, double a_minValue, double a_maxValue)
          Constructor.
Terminal(GPConfiguration a_conf, java.lang.Class a_returnType, double a_minValue, double a_maxValue, boolean a_wholeNumbers)
          Constructor.
Terminal(GPConfiguration a_conf, java.lang.Class a_returnType, double a_minValue, double a_maxValue, boolean a_wholeNumbers, int a_subReturnType)
           
Terminal(GPConfiguration a_conf, java.lang.Class a_returnType, double a_minValue, double a_maxValue, boolean a_wholeNumbers, int a_subReturnType, boolean a_randomize)
           
 
Method Summary
 CommandGene applyMutation(int index, double a_percentage)
          Mutates a CommandGene.
 java.lang.Object clone()
          Clones the object.
 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)
          Returns a string representation of the terminal.
 java.lang.Class getChildType(IGPProgram a_ind, int a_chromNum)
          Gets the type of node allowed from the given child number.
protected  void setRandomValue()
           
protected  void setRandomValue(double a_value)
           
protected  void setRandomValue(float a_value)
           
protected  void setRandomValue(int a_value)
           
protected  void setRandomValue(long a_value)
           
 void setValue(double a_value)
           
 void setValue(float a_value)
           
 void setValue(int a_value)
           
 void setValue(long a_value)
           
 java.lang.String toString()
           
 
Methods inherited from class org.jgap.gp.CommandGene
check, check, cleanup, compareTo, dynamizeArity, ensureUniqueness, ensureUniqueness, ensureUniqueness2, equals, execute_boolean, execute_void, execute, getAllele, getApplicationData, getArity, getArityMax, getArityMin, getCommandType, getEnergy, getGPConfiguration, getInternalValue, getName, getPersistentRepresentation, getPersistentRepresentationExt, getReturnType, getSubChildType, getSubChildTypes, getSubReturnType, hashCode, init, isAffectGlobalState, isCompareApplicationData, isFloatType, isIntegerType, isValid, isValid, setAllele, setApplicationData, setArity, setArityMax, setArityMin, setCompareApplicationData, setEnergy, setNoValidation, setReturnType, setToRandomValue, setValueFromPersistentRepresentation, setValueFromString, size
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Terminal

public Terminal()
         throws InvalidConfigurationException
Throws:
InvalidConfigurationException

Terminal

public Terminal(GPConfiguration a_conf,
                java.lang.Class a_returnType)
         throws InvalidConfigurationException
Throws:
InvalidConfigurationException

Terminal

public Terminal(GPConfiguration a_conf,
                java.lang.Class a_returnType,
                double a_minValue,
                double a_maxValue)
         throws InvalidConfigurationException
Constructor.

Parameters:
a_conf - GPConfiguration
a_returnType - Class
a_minValue - double
a_maxValue - double
Throws:
InvalidConfigurationException
Since:
3.0

Terminal

public Terminal(GPConfiguration a_conf,
                java.lang.Class a_returnType,
                double a_minValue,
                double a_maxValue,
                boolean a_wholeNumbers)
         throws InvalidConfigurationException
Constructor.

Parameters:
a_conf - GPConfiguration
a_returnType - Class
a_minValue - double
a_maxValue - double
a_wholeNumbers - true: only return whole numbers (only relevant when using type double or float)
Throws:
InvalidConfigurationException
Since:
3.2

Terminal

public Terminal(GPConfiguration a_conf,
                java.lang.Class a_returnType,
                double a_minValue,
                double a_maxValue,
                boolean a_wholeNumbers,
                int a_subReturnType)
         throws InvalidConfigurationException
Throws:
InvalidConfigurationException

Terminal

public Terminal(GPConfiguration a_conf,
                java.lang.Class a_returnType,
                double a_minValue,
                double a_maxValue,
                boolean a_wholeNumbers,
                int a_subReturnType,
                boolean a_randomize)
         throws InvalidConfigurationException
Parameters:
a_conf - GPConfiguration
a_returnType - Class
a_minValue - double
a_maxValue - double
a_wholeNumbers - boolean
a_subReturnType - int
a_randomize - true: randomize initial value
Throws:
InvalidConfigurationException
Since:
3.4.1
Method Detail

setRandomValue

protected void setRandomValue(int a_value)

setRandomValue

protected void setRandomValue(long a_value)

setRandomValue

protected void setRandomValue(double a_value)

setRandomValue

protected void setRandomValue(float a_value)

setRandomValue

protected void setRandomValue()

setValue

public void setValue(double a_value)

setValue

public void setValue(float a_value)

setValue

public void setValue(int a_value)

setValue

public void setValue(long a_value)

applyMutation

public CommandGene applyMutation(int index,
                                 double a_percentage)
                          throws InvalidConfigurationException
Description copied from interface: IMutateable
Mutates a CommandGene.

Specified by:
applyMutation in interface IMutateable
Parameters:
index - references the part of a multipart object, normally not relevant
a_percentage - the mutation rate (0.0 to 1.0)
Returns:
the mutant
Throws:
InvalidConfigurationException

toString

public java.lang.String toString()
Specified by:
toString in class CommandGene
Returns:
the string representation of the command. Especially usefull to output a resulting formula in human-readable form.

execute_int

public int execute_int(ProgramChromosome c,
                       int n,
                       java.lang.Object[] args)
Description copied from class: CommandGene
Executes this node as an integer. Override to implement.

Overrides:
execute_int in class CommandGene
Parameters:
c - ignored here
n - ignored here
args - ignored here
Returns:
nothing but exception

execute_long

public long execute_long(ProgramChromosome c,
                         int n,
                         java.lang.Object[] args)
Description copied from class: CommandGene
Executes this node as a long. Override to implement.

Overrides:
execute_long in class CommandGene
Parameters:
c - ignored here
n - ignored here
args - ignored here
Returns:
nothing but exception

execute_float

public float execute_float(ProgramChromosome c,
                           int n,
                           java.lang.Object[] args)
Description copied from class: CommandGene
Executes this node as a float. Override to implement.

Overrides:
execute_float in class CommandGene
Parameters:
c - ignored here
n - ignored here
args - ignored here
Returns:
nothing but exception

execute_double

public double execute_double(ProgramChromosome c,
                             int n,
                             java.lang.Object[] args)
Description copied from class: CommandGene
Executes this node as a double. Override to implement.

Overrides:
execute_double in class CommandGene
Parameters:
c - ignored here
n - ignored here
args - ignored here
Returns:
nothing but exception

execute_object

public java.lang.Object execute_object(ProgramChromosome c,
                                       int n,
                                       java.lang.Object[] args)
Returns a string representation of the terminal.

Overrides:
execute_object in class CommandGene
Parameters:
c - ignored here
n - ignored here
args - ignored here
Returns:
StringBuffer with textual representation of terminal's value
Since:
3.2

getChildType

public java.lang.Class getChildType(IGPProgram a_ind,
                                    int a_chromNum)
Description copied from class: CommandGene
Gets the type of node allowed from the given child number. Should be overridden in subclasses.

Overrides:
getChildType in class CommandGene
Parameters:
a_ind - the individual the child belongs to
a_chromNum - the chromosome number
Returns:
the type of node allowed for that child, or null of no child exists

clone

public java.lang.Object clone()
Clones the object. Simple and straight forward implementation here.

Specified by:
clone in interface ICloneable
Overrides:
clone in class java.lang.Object
Returns:
cloned instance of this object
Since:
3.2

JGAP