ec
Class Species

java.lang.Object
  extended byec.Species
All Implemented Interfaces:
java.lang.Cloneable, Prototype, java.io.Serializable, Setup
Direct Known Subclasses:
GPSpecies, RuleSpecies, VectorSpecies

public abstract class Species
extends java.lang.Object
implements Prototype

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 holds a prototypical breeding pipeline meant to breed this individual. To breed individuals of this species, clone the pipeline and use the clone.

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
classname, inherits and != ec.BreedingPipeline
(the class for the prototypical Breeding Pipeline)

Parameter bases

base.ind i_prototype (the prototypical individual)
base.pipe pipe_prototype (breeding pipeline prototype)

See Also:
Serialized Form

Field Summary
 Individual i_prototype
          The prototypical individual for this species.
static java.lang.String P_INDIVIDUAL
           
static java.lang.String P_PIPE
           
 BreedingPipeline pipe_prototype
           
 
Constructor Summary
Species()
           
 
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  Individual newIndividual(EvolutionState state, Subpopulation _population, Fitness _fitness)
          override this to provide a brand-new individual to fill in a population.
 Individual newIndividual(EvolutionState state, Subpopulation _population, Fitness _fitness, java.io.DataInput dataInput)
          Override this to provide an individual read from a binary stream, likely using readIndividual(...).
 Individual newIndividual(EvolutionState state, Subpopulation _population, Fitness _fitness, java.io.LineNumberReader reader)
          Override this to provide an individual read from a file; the individual will appear as it was written by printIndividual(...).
 void setup(EvolutionState state, Parameter base)
          The default version of setup(...) loads requested pipelines and calls setup(...) on them and normalizes their probabilities.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ec.Prototype
defaultBase
 

Field Detail

P_INDIVIDUAL

public static final java.lang.String P_INDIVIDUAL
See Also:
Constant Field Values

P_PIPE

public static final java.lang.String P_PIPE
See Also:
Constant Field Values

i_prototype

public Individual i_prototype
The prototypical individual for this species.


pipe_prototype

public BreedingPipeline pipe_prototype
Constructor Detail

Species

public Species()
Method Detail

clone

public java.lang.Object clone()
Description copied from interface: Prototype
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

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.

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.

Specified by:
clone in interface Prototype

newIndividual

public abstract Individual newIndividual(EvolutionState state,
                                         Subpopulation _population,
                                         Fitness _fitness)
override this to provide a brand-new individual to fill in a population. The CloneNotSupportedException permits you to use protoClone() rather than protoCloneSimple(), for efficiency gains. It's assumed that the thread is thread 0.


newIndividual

public Individual newIndividual(EvolutionState state,
                                Subpopulation _population,
                                Fitness _fitness,
                                java.io.LineNumberReader reader)
                         throws java.io.IOException
Override this to provide an individual read from a file; the individual will appear as it was written by printIndividual(...). You should read and set up the fitness as well. Don't close the file. The default version of this method throws an error.

Throws:
java.io.IOException

newIndividual

public Individual newIndividual(EvolutionState state,
                                Subpopulation _population,
                                Fitness _fitness,
                                java.io.DataInput dataInput)
                         throws java.io.IOException
Override this to provide an individual read from a binary stream, likely using readIndividual(...). You should read and set up the fitness as well. Don't close the file. The default version of this method throws an error.

Throws:
java.io.IOException

setup

public void setup(EvolutionState state,
                  Parameter base)
The default version of setup(...) loads requested pipelines and calls setup(...) on them and normalizes their probabilities. If your individual prototype might need to know special things about the species (like parameters stored in it), then when you override this setup method, you'll need to set those parameters BEFORE you call super.setup(...), because the setup(...) code in Species sets up the prototype.

Specified by:
setup in interface Prototype
See Also:
Prototype.setup(EvolutionState,Parameter)