org.jgap.gp.impl
Class GPProgram
- java.lang.Object
-
- org.jgap.gp.GPProgramBase
-
- org.jgap.gp.impl.GPProgram
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, IGPProgram, IBusinessKey, ICloneable
public class GPProgram extends GPProgramBase implements java.io.Serializable, java.lang.Comparable, ICloneable, IBusinessKey
A GP program contains 1..n ProgramChromosome's.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description GPProgram()Default constructor, only for dynamic instantiation.GPProgram(GPConfiguration a_conf, java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_maxNodes)Master constructor.GPProgram(GPConfiguration a_conf, int a_numChromosomes)Sort of minimalistic constructor.GPProgram(IGPProgram a_prog)Constructor to initialize a GPProgram with values of another GPProgram.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Objectclone()intcompareTo(java.lang.Object a_other)Compares the given program to this program.booleanexecute_boolean(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as a boolean function.doubleexecute_double(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as a double function.floatexecute_float(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as a float function.intexecute_int(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as an integer function.java.lang.Objectexecute_object(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as an object function.voidexecute_void(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as an object function.java.lang.StringgetBusinessKey()ProgramChromosomegetChromosome(int a_index)intgetCommandOfClass(int a_chromosomeNum, java.lang.Class a_class)Searches for a chromosome that has the given class and returns its index.java.lang.StringgetPersistentRepresentation()voidgrowOrFull(java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets)Initialize this program by using given chromosomes.voidgrowOrFull(int a_depth, boolean a_grow, int a_maxNodes, boolean[] a_fullModeAllowed, int a_tries)Initialize the chromosomes within this GP program using the grow or the full method.voidsetChromosome(int a_index, ProgramChromosome a_chrom)Sets the given chromosome at the given index.intsize()java.lang.StringtoString(int a_startNode)Builds a string that represents the output of the GPProgram in left-hand-notion.java.lang.StringtoStringDebug()Builds a string that represents the debug output of the GPProgram.java.lang.StringtoStringNorm(int a_startNode)Builds a string that represents the normalized output of the GPProgram.-
Methods inherited from class org.jgap.gp.GPProgramBase
calcFitnessValue, equals, getApplicationData, getArgType, getArgTypes, getFitnessValue, getFitnessValueDirectly, getGPConfiguration, getMaxDepths, getMaxNodes, getMinDepths, getNodeSet, getNodeSets, getType, getTypes, setApplicationData, setArgTypes, setFitnessValue, setMaxDepths, setMaxNodes, setMinDepths, setNodeSets, setTypes
-
-
-
-
Constructor Detail
-
GPProgram
public GPProgram() throws java.lang.ExceptionDefault constructor, only for dynamic instantiation.- Throws:
java.lang.Exception- Since:
- 3.3.4
-
GPProgram
public GPProgram(GPConfiguration a_conf, java.lang.Class[] a_types, java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets, int[] a_minDepths, int[] a_maxDepths, int a_maxNodes) throws InvalidConfigurationException
Master constructor.- Parameters:
a_conf- the configuration to usea_types- the type of each chromosome, the length is the number of chromosomesa_argTypes- the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosomea_nodeSets- the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodesa_minDepths- contains the minimum depth allowed for each chromosomea_maxDepths- contains the maximum depth allowed for each chromosomea_maxNodes- reserve space for a_maxNodes number of nodes- Throws:
InvalidConfigurationException- Since:
- 3.0
-
GPProgram
public GPProgram(IGPProgram a_prog) throws InvalidConfigurationException
Constructor to initialize a GPProgram with values of another GPProgram.- Parameters:
a_prog- the GPProgram to read the initialization values from- Throws:
InvalidConfigurationException- Since:
- 3.0
-
GPProgram
public GPProgram(GPConfiguration a_conf, int a_numChromosomes) throws InvalidConfigurationException
Sort of minimalistic constructor. Use only if you are aware of what you do.- Parameters:
a_conf- the configuration to usea_numChromosomes- the number of chromosomes to use with this program.- Throws:
InvalidConfigurationException- Since:
- 3.0
-
-
Method Detail
-
getChromosome
public ProgramChromosome getChromosome(int a_index)
- Specified by:
getChromosomein interfaceIGPProgram- Parameters:
a_index- the chromosome to get- Returns:
- the ProgramChromosome with the given index
- Since:
- 3.0
-
setChromosome
public void setChromosome(int a_index, ProgramChromosome a_chrom)Sets the given chromosome at the given index.- Specified by:
setChromosomein interfaceIGPProgram- Parameters:
a_index- sica_chrom- sic- Since:
- 3.0
-
growOrFull
public void growOrFull(int a_depth, boolean a_grow, int a_maxNodes, boolean[] a_fullModeAllowed, int a_tries)Initialize the chromosomes within this GP program using the grow or the full method.- Parameters:
a_depth- the maximum depth of the chromosome to createa_grow- true: use grow method; false: use full methoda_maxNodes- maximum number of nodes alloweda_fullModeAllowed- for each chromosome: true means full mode allowed, otherwise use grow modea_tries- maximum number of tries to create a valid program- Since:
- 3.0
-
growOrFull
public void growOrFull(java.lang.Class[][] a_argTypes, CommandGene[][] a_nodeSets)Initialize this program by using given chromosomes.- Parameters:
a_argTypes- the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosomea_nodeSets- the nodes which are allowed to be used by each chromosome,- Since:
- 3.2.2
-
size
public int size()
- Specified by:
sizein interfaceIGPProgram- Returns:
- the number of chromosomes in the program
- Since:
- 3.0
-
toString
public java.lang.String toString(int a_startNode)
Builds a string that represents the output of the GPProgram in left-hand-notion.- Parameters:
a_startNode- the node to start with- Returns:
- output in left-hand notion
- Since:
- 3.0
-
toStringNorm
public java.lang.String toStringNorm(int a_startNode)
Builds a string that represents the normalized output of the GPProgram.- Specified by:
toStringNormin interfaceIGPProgram- Parameters:
a_startNode- the node to start with- Returns:
- output in normalized notion
- Since:
- 3.0
-
toStringDebug
public java.lang.String toStringDebug()
Builds a string that represents the debug output of the GPProgram.- Returns:
- class names of all program chromosomes
- Since:
- 3.0
-
execute_int
public int execute_int(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as an integer function.- Specified by:
execute_intin interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to executea_args- the arguments to use- Returns:
- the integer return value
- Since:
- 3.0
-
execute_float
public float execute_float(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as a float function.- Specified by:
execute_floatin interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to executea_args- the arguments to use- Returns:
- the floar return value
- Since:
- 3.0
-
execute_double
public double execute_double(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as a double function.- Specified by:
execute_doublein interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to executea_args- the arguments to use- Returns:
- the double return value
- Since:
- 3.0
-
execute_boolean
public boolean execute_boolean(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as a boolean function.- Specified by:
execute_booleanin interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to executea_args- the arguments to use- Returns:
- the boolean return value
- Since:
- 3.2
-
execute_object
public java.lang.Object execute_object(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as an object function.- Specified by:
execute_objectin interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to executea_args- the arguments to use- Returns:
- the object return value
- Since:
- 3.0
-
execute_void
public void execute_void(int a_chromosomeNum, java.lang.Object[] a_args)Executes the given chromosome as an object function.- Specified by:
execute_voidin interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to executea_args- the arguments to use- Since:
- 3.0
-
getCommandOfClass
public int getCommandOfClass(int a_chromosomeNum, java.lang.Class a_class)Searches for a chromosome that has the given class and returns its index.- Specified by:
getCommandOfClassin interfaceIGPProgram- Parameters:
a_chromosomeNum- the index of the chromosome to start the search witha_class- the class to find- Returns:
- the index of the first chromosome found that is of a_class, or -1
- Since:
- 3.0
-
compareTo
public int compareTo(java.lang.Object a_other)
Compares the given program to this program.- Specified by:
compareToin interfacejava.lang.Comparable- Parameters:
a_other- the program against which to compare this program- Returns:
- a negative number if this program is "less than" the given program, zero if they are equal to each other, and a positive number if this program is "greater than" the given program
- Since:
- 3.0
-
clone
public java.lang.Object clone()
- Specified by:
clonein interfaceICloneable- Specified by:
clonein classGPProgramBase- Returns:
- deep clone of the object instance
- Since:
- 3.2
-
getPersistentRepresentation
public java.lang.String getPersistentRepresentation()
- Specified by:
getPersistentRepresentationin interfaceIGPProgram- Returns:
- the persistent representation of the GP program, including all chromosomes
- Since:
- 3.3
-
getBusinessKey
public java.lang.String getBusinessKey()
- Specified by:
getBusinessKeyin interfaceIBusinessKey- Returns:
- hopefully unique key representing the state of the GPProgram
- Since:
- 3.4
-
-
DMelt 3.0 © DataMelt by jWork.ORG