|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Individual
ec.gp.GPIndividual
GPIndividual is an Individual used for GP evolution runs. GPIndividuals contain, at the very least, a nonempty array of GPTrees. You can use GPIndividual directly, or subclass it to extend it as you see fit.
GPIndividuals have two clone methods. The standard protoClone method in GPIndividual is NOT a deep clone. If you require a deep clone, Individual provides the deepClone method, which all Individuals should properly override to ensure deep cloning.
In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways.
In general, the various readers and writers do three things: they tell the Fitness to read/write itself, they read/write the evaluated flag, and they read/write the GPTree array (by having each GPTree read/write itself). If you add instance variables to GPIndividual, you'll need to read/write those variables as well.
Parameters
base.numtrees int >= 1 |
(number of trees in the GPIndividual) |
base.tree.n classname, inherits or = ec.gp.GPTree |
(class of tree n in the individual) |
Default Base
gp.individual
Parameter bases
base.tree.n | tree n in the individual |
Field Summary | |
static java.lang.String |
EVALUATED_PREAMBLE
|
static java.lang.String |
P_INDIVIDUAL
|
static java.lang.String |
P_NUMTREES
|
static java.lang.String |
P_TREE
|
GPTree[] |
trees
|
Fields inherited from class ec.Individual |
evaluated, fitness, species |
Constructor Summary | |
GPIndividual()
|
Method Summary | |
java.lang.Object |
clone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
Parameter |
defaultBase()
Returns the default base for this prototype. |
boolean |
equals(java.lang.Object ind)
Returns true if I am genetically "equal" to ind. |
int |
hashCode()
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code. |
GPIndividual |
lightClone()
Like clone(), but doesn't force the GPTrees to deep-clone themselves. |
void |
printIndividual(EvolutionState state,
int log,
int verbosity)
Prints the individual in a way that it can be read in again by computer. |
void |
printIndividual(EvolutionState state,
java.io.PrintWriter writer)
Prints the individual in a way that it can be read in again by computer. |
void |
printIndividualForHumans(EvolutionState state,
int log,
int verbosity)
A printer for the individual in a reasonable human-readable, fashion. |
void |
readGenotype(EvolutionState state,
java.io.DataInput dataInput)
|
void |
readIndividual(EvolutionState state,
java.io.LineNumberReader reader)
Reads in the individual from a form printed by printIndividual(). |
void |
setup(EvolutionState state,
Parameter base)
Sets up a prototypical GPIndividual with those features which it shares with other GPIndividuals in its species, and nothing more. |
long |
size()
Returns the "size" of the individual, namely, the number of nodes in all of its subtrees. |
void |
writeGenotype(EvolutionState state,
java.io.DataOutput dataOutput)
|
Methods inherited from class ec.Individual |
genotypeToString, genotypeToStringForHumans, parseGenotype, readIndividual, toString, writeIndividual |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String P_INDIVIDUAL
public static final java.lang.String P_NUMTREES
public static final java.lang.String P_TREE
public static final java.lang.String EVALUATED_PREAMBLE
public GPTree[] trees
Constructor Detail |
public GPIndividual()
Method Detail |
public Parameter defaultBase()
Prototype
public boolean equals(java.lang.Object ind)
Individual
equals
in class Individual
public int hashCode()
Individual
hashCode
in class Individual
public void setup(EvolutionState state, Parameter base)
setup
in interface Prototype
setup
in class Individual
public void printIndividualForHumans(EvolutionState state, int log, int verbosity)
printIndividualForHumans
in class Individual
public void printIndividual(EvolutionState state, int log, int verbosity)
printIndividual
in class Individual
public void printIndividual(EvolutionState state, java.io.PrintWriter writer)
printIndividual
in class Individual
public void writeGenotype(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
writeGenotype
in class Individual
java.io.IOException
public void readGenotype(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
readGenotype
in class Individual
java.io.IOException
public void readIndividual(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
readIndividual
in class Individual
java.io.IOException
public java.lang.Object clone()
Prototype
The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:
Implementations.
public Object protoClone()
{
return super.clone();
}
public Object protoClone()
{
myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
public Object protoClone()
{
MyObject myobj = (MyObject)(super.protoClone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).
In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.
The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.
clone
in interface Prototype
clone
in class Individual
public GPIndividual lightClone()
public long size()
size
in class Individual
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |