|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Individual
ec.vector.VectorIndividual
ec.vector.IntegerVectorIndividual
IntegerVectorIndividual is a VectorIndividual whose genome is an array of ints. Gene values may range from species.mingene(x) to species.maxgene(x), inclusive. The default mutation method randomizes genes to new values in this range, with species.mutationProbability.
Default Base
vector.int-vect-ind
Field Summary | |
int[] |
genome
|
static java.lang.String |
P_INTEGERVECTORINDIVIDUAL
|
Fields inherited from class ec.Individual |
evaluated, EVALUATED_PREAMBLE, fitness, species |
Constructor Summary | |
IntegerVectorIndividual()
|
Method Summary | |
Parameter |
defaultBase()
Returns the default base for this prototype. |
void |
defaultCrossover(EvolutionState state,
int thread,
VectorIndividual ind)
Destructively crosses over the individual with another in some default manner. |
void |
defaultMutate(EvolutionState state,
int thread)
Destructively mutates the individual in some default manner. |
boolean |
equals(java.lang.Object ind)
Returns true if I am genetically "equal" to ind. |
long |
genomeLength()
Returns the length of the gene array. |
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. |
java.lang.Object |
getGenome()
Returns the gene array. |
int |
hashCode()
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code. |
void |
join(java.lang.Object[] pieces)
Joins the n pieces and sets the genome to their concatenation. |
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. |
java.lang.Object |
protoClone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
void |
readGenotype(EvolutionState state,
java.io.DataInput dataInput)
|
void |
reset(EvolutionState state,
int thread)
Initializes the individual by randomly choosing Integers uniformly from mingene to maxgene. |
void |
setGenome(java.lang.Object gen)
Sets the gene array. |
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. |
void |
split(int[] points,
java.lang.Object[] pieces)
Splits the genome into n pieces, according to points, which *must* be sorted. |
void |
writeGenotype(EvolutionState state,
java.io.DataOutput dataOutput)
|
Methods inherited from class ec.vector.VectorIndividual |
size |
Methods inherited from class ec.Individual |
deepClone, printIndividual, printIndividual, printIndividualForHumans, protoCloneSimple, readIndividual, readIndividual, toString, writeIndividual |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String P_INTEGERVECTORINDIVIDUAL
public int[] genome
Constructor Detail |
public IntegerVectorIndividual()
Method Detail |
public Parameter defaultBase()
Prototype
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
protoClone
in class Individual
java.lang.CloneNotSupportedException
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 class Individual
public void defaultCrossover(EvolutionState state, int thread, VectorIndividual ind)
VectorIndividual
defaultCrossover
in class VectorIndividual
public void split(int[] points, java.lang.Object[] pieces)
split
in class VectorIndividual
public void join(java.lang.Object[] pieces)
join
in class VectorIndividual
public void defaultMutate(EvolutionState state, int thread)
defaultMutate
in class VectorIndividual
public void reset(EvolutionState state, int thread)
reset
in class VectorIndividual
public int hashCode()
Individual
hashCode
in class Individual
public java.lang.String genotypeToStringForHumans()
Individual
genotypeToStringForHumans
in class Individual
public java.lang.String genotypeToString()
Individual
genotypeToString
in class Individual
protected void parseGenotype(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
Individual
parseGenotype
in class Individual
java.io.IOException
java.lang.CloneNotSupportedException
public boolean equals(java.lang.Object ind)
Individual
equals
in class Individual
public java.lang.Object getGenome()
VectorIndividual
getGenome
in class VectorIndividual
public void setGenome(java.lang.Object gen)
VectorIndividual
setGenome
in class VectorIndividual
public long genomeLength()
VectorIndividual
genomeLength
in class VectorIndividual
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, java.lang.CloneNotSupportedException
readGenotype
in class Individual
java.io.IOException
java.lang.CloneNotSupportedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |