|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Individual
public abstract class 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 their genetic material should not be modified. This protocol helps insure that they are safe to read under multithreaded conditions. You can violate this protocol, but try to do so when you know you have only have a single thread.
In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways.
Since individuals should be largely immutable, why is there a readIndividual method? after all this method doesn't create a new individual -- it just erases the existing one. This is largely historical; but the method is used underneath by the various newIndividual methods in Species, which do create new individuals read from files. If you're trying to create a brand new individual read from a file, look in Species.
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. |
static java.lang.String |
P_INDIVIDUAL
A reasonable parameter base element for individuals |
Species |
species
The species of the Individual. |
Constructor Summary | |
---|---|
Individual()
|
Method Summary | |
---|---|
java.lang.Object |
clone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
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); |
void |
readGenotype(EvolutionState state,
java.io.DataInput dataInput)
Reads in the genotypic information from a DataInput, erasing the previous genotype of this Individual. |
void |
readIndividual(EvolutionState state,
java.io.DataInput dataInput)
Reads the binary form of an individual from a DataInput, erasing the previous information stored in this Individual. |
void |
readIndividual(EvolutionState state,
java.io.LineNumberReader reader)
Reads in the individual from a form printed by printIndividual(), erasing the previous information stored in this Individual. |
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)
Writes the genotypic information to a 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 |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ec.Prototype |
---|
defaultBase |
Field Detail |
---|
public static final java.lang.String P_INDIVIDUAL
public static final java.lang.String EVALUATED_PREAMBLE
public Fitness fitness
public Species species
public boolean evaluated
Constructor Detail |
---|
public Individual()
Method Detail |
---|
public java.lang.Object clone()
Prototype
Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:
Implementations.
public Object clone()
{
try
{
return super.clone();
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
public Object clone()
{
try
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
return myobj;
}
public Object clone()
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
return myobj;
}
clone
in interface Prototype
clone
in class java.lang.Object
public long size()
public abstract boolean equals(java.lang.Object ind)
equals
in class java.lang.Object
public abstract int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
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
setup
in interface Setup
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 calls Individual.genotypeToStringForHumans(). Feel free to override this to produce more sophisticated behavior, though it is rare to need to -- instead you could just override genotypeToStringForHumans().
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 calls Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior, though it is rare to need to -- instead you could just override genotypeToString().
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 calls Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior, though it is rare to need to -- instead you could just override genotypeToString().
public void readIndividual(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
java.io.IOException
protected void parseGenotype(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
java.io.IOException
public void writeIndividual(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
java.io.IOException
public void writeGenotype(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
dataOutput.writeInt(integers.length); for(int x=0;x
java.io.IOException
public void readGenotype(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
integers = new int[dataInput.readInt()]; for(int x=0;x
java.io.IOException
public void readIndividual(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |