|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ec.Species
Species is a prototype which defines the features for a set of individuals in the population. Typically, individuals may breed if they belong to the same species (but it's not a hard-and-fast rule). Each Subpopulation has one Species object which defines the species for individuals in that Subpopulation.
Species are generally responsible for creating individuals, through their newIndividual(...) method. This method usually clones its prototypical individual and makes some additional modifications to the clone, then returns it.
Species also contain an array of breeding pipelines, which are mechanisms by which individuals may breed to make new individuals in a new population. For example, selection followed by crossover followed by a small amount of mutation might be a breeding pipeline. Breeding Pipelines are per-species. The ones stored in a species are prototypes, and at breeding time, they are generally cloned, one set of BreedingPipelines per thread, to breed the new population.
Parameters
base.ind classname, inherits and != ec.Individual |
(the class for the prototypical individual for the species) |
base.numpipes int >= 1 |
(total number of breeding pipelines for the species) |
base.pipe.n classname, inherits and != ec.BreedingPipeline |
(the class for prototypical Breeding Pipeline #n) |
Parameter bases
base.ind | i_prototype (the prototypical individual) |
base.pipe.n | p_breedingpipelines[n] (breeding pipeline prototype n) |
Field Summary | |
Individual |
i_prototype
The prototypical individual for this species. |
BreedingPipeline[] |
p_breedingpipelines
This can be an array of breeding pipelines which by default is the set of breeding pipelines for this Species. |
static java.lang.String |
P_INDIVIDUAL
|
static java.lang.String |
P_NUMPIPES
|
static java.lang.String |
P_PIPE
|
Constructor Summary | |
Species()
|
Method Summary | |
abstract Individual |
newIndividual(EvolutionState state,
Subpopulation _population,
Fitness _fitness)
override this to provide a brand-new individual to fill in a population. |
abstract Individual |
newIndividual(EvolutionState state,
Subpopulation _population,
Fitness _fitness,
int thread,
java.io.LineNumberReader reader)
override this to provide an individual read from a file; the individual will appear as it was written by printIndividual(...). |
BreedingPipeline[] |
pipelines(EvolutionState state)
Returns a freshly cloned set of pipelines for a thread to use. |
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 |
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. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final java.lang.String P_INDIVIDUAL
public static final java.lang.String P_PIPE
public static final java.lang.String P_NUMPIPES
public Individual i_prototype
public BreedingPipeline[] p_breedingpipelines
When you set this up, you must also manually set the default probabilities for this breeding pipeline array. To do this, set the probability field of each pipeline in the array to some value between 0.0 and 1.0, representing its probability of being chosen over other pipelines. These values don't have to be normalized -- that'll be done elsewhere for you anyway.
The breeding pipelines here won't be directly used; instead, they'll be copied first (with protoClone()), and the copies will be used instead. They may be copied more than once.
Constructor Detail |
public Species()
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 Individual newIndividual(EvolutionState state, Subpopulation _population, Fitness _fitness) throws java.lang.CloneNotSupportedException
public abstract Individual newIndividual(EvolutionState state, Subpopulation _population, Fitness _fitness, int thread, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
public void setup(EvolutionState state, Parameter base)
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.
public BreedingPipeline[] pipelines(EvolutionState state)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |