|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Individual
An Individual is an item in the EC population stew which is evaluated and assigned a fitness which determines its likelihood of selection. Individuals are created most commonly by the newIndividual(...) method of the ec.Species class. In general Individuals are immutable. That is, once they are created they should not be modified. This protocol helps insure that they are safe to read under multithreaded conditions.
Field Summary | |
boolean |
evaluated
Has the individual been evaluated and its fitness determined yet? |
static java.lang.String |
EVALUATED_PREAMBLE
A string appropriate to put in front of whether or not the individual has been printed. |
Fitness |
fitness
The fitness of the Individual. |
Species |
species
The species of the Individual. |
Constructor Summary | |
Individual()
|
Method Summary | |
Individual |
deepClone()
Guaranteed DEEP-CLONES the individual. |
abstract boolean |
equals(java.lang.Object ind)
Returns true if I am genetically "equal" to ind. |
java.lang.String |
genotypeToString()
Print to a string the genotype of the Individual in a fashion intended to be parsed in again via parseGenotype(...). |
java.lang.String |
genotypeToStringForHumans()
Print to a string the genotype of the Individual in a fashion readable by humans, and not intended to be parsed in again. |
abstract int |
hashCode()
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code. |
protected void |
parseGenotype(EvolutionState state,
java.io.LineNumberReader reader)
This method is used only by the default version of readIndividual(state,reader), and it is intended to be overridden to parse in that part of the individual that was outputted in the genotypeToString() method. |
void |
printIndividual(EvolutionState state,
int log,
int verbosity)
Should print the individual in a way that can be read by computer, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,verbosity); |
void |
printIndividual(EvolutionState state,
java.io.PrintWriter writer)
Should print the individual in a way that can be read by computer, including its fitness. |
void |
printIndividualForHumans(EvolutionState state,
int log,
int verbosity)
Should print the individual out in a pleasing way for humans, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitnessForHumans(state,log,verbosity); |
java.lang.Object |
protoClone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
java.lang.Object |
protoCloneSimple()
This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final. |
void |
readGenotype(EvolutionState state,
java.io.DataInput dataInput)
|
void |
readIndividual(EvolutionState state,
java.io.DataInput dataInput)
Reads the binary form of an individual from a 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 the object by reading it from the parameters stored in state, built off of the parameter base base. |
long |
size()
Returns the "size" of the individual. |
java.lang.String |
toString()
Overridden here because hashCode() is not expected to return the pointer to the object. |
void |
writeGenotype(EvolutionState state,
java.io.DataOutput dataOutput)
|
void |
writeIndividual(EvolutionState state,
java.io.DataOutput dataOutput)
Writes the binary form of an individual out to a DataOutput. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ec.Prototype |
defaultBase |
Field Detail |
public static final java.lang.String EVALUATED_PREAMBLE
public Fitness fitness
public Species species
public boolean evaluated
Constructor Detail |
public Individual()
Method Detail |
public Individual deepClone()
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
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() throws CloneNotSupportedException
{
return super.clone();
}
public Object protoClone() throws CloneNotSupportedException
{
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() throws CloneNotSupportedException
{
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.
protoClone
in interface Prototype
java.lang.CloneNotSupportedException
public final java.lang.Object protoCloneSimple()
Prototype
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
protoCloneSimple
in interface Prototype
public long size()
public abstract boolean equals(java.lang.Object ind)
public abstract int hashCode()
public java.lang.String toString()
public java.lang.String genotypeToStringForHumans()
public java.lang.String genotypeToString()
public void setup(EvolutionState state, Parameter base)
Prototype
For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.
setup
in interface Prototype
public void printIndividualForHumans(EvolutionState state, int log, int verbosity)
The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then Individual.genotypeToStringForHumans(). Feel free to override this to produce more sophisticated behavior.
public void printIndividual(EvolutionState state, int log, int verbosity)
The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior.
public void printIndividual(EvolutionState state, java.io.PrintWriter writer)
The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior.
public void readIndividual(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
java.io.IOException
java.lang.CloneNotSupportedException
protected void parseGenotype(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
java.io.IOException
java.lang.CloneNotSupportedException
public void writeIndividual(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
super.writeIndividual(state,dataOutput); dataOutput.writeInt(integers.length); for(int x=0;x
java.io.IOException
public void writeGenotype(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
java.io.IOException
public void readGenotype(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException, java.lang.CloneNotSupportedException
java.io.IOException
java.lang.CloneNotSupportedException
public void readIndividual(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException, java.lang.CloneNotSupportedException
super.readIndividual(state,dataInput); integers = new int[dataInput.read(integers.length); for(int x=0;x
java.io.IOException
java.lang.CloneNotSupportedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |