|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ec.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? |
Fitness |
fitness
The fitness of the Individual. |
Constructor Summary | |
Individual()
|
Method Summary | |
abstract boolean |
equals(java.lang.Object ind)
Returns true if I am genetically "equal" to ind. |
abstract int |
hashCode()
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code. |
abstract 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); |
abstract void |
printIndividual(EvolutionState state,
int thread,
java.io.PrintWriter writer)
Should print the individual in a way that can be read by computer, including its fitness. |
abstract 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. |
abstract void |
readIndividual(EvolutionState state,
int thread,
java.io.LineNumberReader reader)
Reads in the individual from a form printed by printIndividual(). |
abstract void |
setup(EvolutionState state,
Parameter base)
This should be used to set up only those things which you share in common with all other individuals in your species; individual-specific items which make you you should be filled in by Species.newIndividual(...), and modified by breeders. |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public Fitness fitness
public boolean evaluated
Constructor Detail |
public Individual()
Method Detail |
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
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.
public final java.lang.Object protoCloneSimple()
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
public abstract boolean equals(java.lang.Object ind)
public abstract int hashCode()
public abstract void setup(EvolutionState state, Parameter base)
Prototype.setup(EvolutionState,Parameter)
public abstract void printIndividualForHumans(EvolutionState state, int log, int verbosity)
public abstract void printIndividual(EvolutionState state, int log, int verbosity)
public abstract void printIndividual(EvolutionState state, int thread, java.io.PrintWriter writer)
public abstract void readIndividual(EvolutionState state, int thread, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |