public abstract class Individual extends Object implements Prototype, Comparable
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.
Individuals are Comparable: if you sort Individuals, the FITTER individuals will appear EARLIER in a list or array.
Modifier and Type | Field and Description |
---|---|
boolean |
evaluated
Has the individual been evaluated and its fitness determined yet?
|
static 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 String |
P_INDIVIDUAL
A reasonable parameter base element for individuals
|
Species |
species
The species of the Individual.
|
Constructor and Description |
---|
Individual() |
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Creates a new individual cloned from a prototype,
and suitable to begin use in its own evolutionary
context.
|
int |
compareTo(Object o)
Returns -1 if I am BETTER in some way than the other Individual, 1 if the other Individual is BETTER than me,
and 0 if we are equivalent.
|
double |
distanceTo(Individual otherInd)
Returns the metric distance to another individual, if such a thing can be measured.
|
abstract boolean |
equals(Object ind)
Returns true if I am genetically "equal" to ind.
|
String |
genotypeToString()
Print to a string the genotype of the Individual in a fashion intended
to be parsed in again via parseGenotype(...).
|
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.
|
void |
merge(EvolutionState state,
Individual other)
Replaces myself with the other Individual, while merging our evaluation results together.
|
protected void |
parseGenotype(EvolutionState state,
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)
Should print the individual in a way that can be read by computer,
including its fitness, with a verbosity of Output.V_NO_GENERAL.
|
void |
printIndividual(EvolutionState state,
int log,
int verbosity)
Deprecated.
Verbosity no longer used.
|
void |
printIndividual(EvolutionState state,
PrintWriter writer)
Should print the individual in a way that can be read by computer,
including its fitness.
|
void |
printIndividualForHumans(EvolutionState state,
int log)
Should print the individual out in a pleasing way for humans,
with a verbosity of Output.V_NO_GENERAL.
|
void |
printIndividualForHumans(EvolutionState state,
int log,
int verbosity)
Deprecated.
Verbosity no longer used.
|
void |
readGenotype(EvolutionState state,
DataInput dataInput)
Reads in the genotypic information from a DataInput, erasing the previous genotype
of this Individual.
|
void |
readIndividual(EvolutionState state,
DataInput dataInput)
Reads the binary form of an individual from a DataInput, erasing the previous
information stored in this Individual.
|
void |
readIndividual(EvolutionState state,
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)
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.
|
long |
size()
Returns the "size" of the individual.
|
String |
toString()
Overridden here because hashCode() is not expected to return the pointer
to the object.
|
void |
writeGenotype(EvolutionState state,
DataOutput dataOutput)
Writes the genotypic information to a DataOutput.
|
void |
writeIndividual(EvolutionState state,
DataOutput dataOutput)
Writes the binary form of an individual out to a DataOutput.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
defaultBase
public static final String P_INDIVIDUAL
public static final String EVALUATED_PREAMBLE
public Fitness fitness
public Species species
public boolean evaluated
public 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;
}
public long size()
public abstract boolean equals(Object ind)
public abstract int hashCode()
public String toString()
public String genotypeToStringForHumans()
public String genotypeToString()
public void setup(EvolutionState state, Parameter base)
setup
in interface Prototype
setup
in interface Setup
Prototype.setup(EvolutionState,Parameter)
public void printIndividualForHumans(EvolutionState state, int log)
public final 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)
public final 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, 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, LineNumberReader reader) throws IOException
IOException
protected void parseGenotype(EvolutionState state, LineNumberReader reader) throws IOException
IOException
public void writeIndividual(EvolutionState state, DataOutput dataOutput) throws IOException
IOException
public void writeGenotype(EvolutionState state, DataOutput dataOutput) throws IOException
dataOutput.writeInt(integers.length); for(int x=0;x
IOException
public void readGenotype(EvolutionState state, DataInput dataInput) throws IOException
integers = new int[dataInput.readInt()]; for(int x=0;x
IOException
public void readIndividual(EvolutionState state, DataInput dataInput) throws IOException
IOException
public double distanceTo(Individual otherInd)
public int compareTo(Object o)
compareTo
in interface Comparable
public void merge(EvolutionState state, Individual other)
What is the purpose of this method? When coevolution is done in combination with distributed evaluation, an Individual may be sent to multiple remote sites to be tested in different trials prior to having a completed fitness assessed. As those trials complete, we need a way to merge them together. By default this method simply merges the trial arrays (using fitness.merge(...)), and determines the "best" context, then copies the other Individual to me. But if you store additional trial results outside fitness---for example, if you keep around the best collaborators from coevolution, say---you may need a way to guarantee that this Individual reflects the most up to date information about recent trials arriving via the other Individual. In this case, override the method and perform merging by hand.
Copyright © 2019. All rights reserved.