ec
Class BreedingPipeline

java.lang.Object
  |
  +--ec.BreedingSource
        |
        +--ec.BreedingPipeline
Direct Known Subclasses:
BufferedBreedingPipeline, ForceBreedingPipeline, GPBreedingPipeline, MultiBreedingPipeline

public abstract class BreedingPipeline
extends BreedingSource

A BreedingPipeline is a BreedingSource which provides "fresh" individuals which can be used to fill a new population. BreedingPipelines might include Crossover pipelines, various Mutation pipelines, etc. This abstract class provides some default versions of various methods to simplify matters for you. It also contains an array of breeding sources for your convenience. You don't have to use them of course, but this means you have to customize the default methods below to make sure they get distributed to your special sources. Note that these sources may contain references to the same object -- they're not necessarily distinct. This is to provide both some simple DAG features and also to conserve space.

Parameters
base.num-sources
int >= 1
(User-specified number of sources to the pipeline. Some pipelines have hard-coded numbers of sources; others indicate (with the java constant DYNAMIC_SOURCES) that the number of sources is determined by this user parameter instead.)
base.source.n
classname, inherits and != BreedingSource, or the value same
(Source n for this BreedingPipeline. If the value is set to same, then this source is the exact same source object as base.source.n-1, and further parameters for this object will be ignored and treated as the same as those for n-1. same is not valid for base.source.0)

Parameter bases
base.source.n
Source n

See Also:
Serialized Form

Field Summary
static int DYNAMIC_SOURCES
          Indicates that the number of sources is variable and determined by the user in the parameter file.
static java.lang.String P_NUMSOURCES
          Standard parameter for number of sources (only used if numSources returns DYNAMIC_SOURCES
static java.lang.String P_SOURCE
          Standard parameter for individual-selectors associated with a BreedingPipeline
 BreedingSource[] sources
          Array of sources feeding the pipeline
static java.lang.String V_SAME
          Indicates that a source is the exact same source as the previous source.
 
Fields inherited from class ec.BreedingSource
CHECKBOUNDARY, DEFAULT_PRODUCED, NO_PROBABILITY, P_PROB, probability, UNUSED
 
Constructor Summary
BreedingPipeline()
           
 
Method Summary
abstract  int numSources()
          Returns the number of sources to this pipeline.
 void preparePipeline(java.lang.Object hook)
          A hook which should be passed to all your subsidiary breeding sources.
 void prepareToProduce(EvolutionState state, int subpopulation, int thread)
          Called before produce(...), usually once a generation, or maybe only once if you're doing steady-state evolution, to let the breeding source "warm up" prior to producing.
 boolean produces(EvolutionState state, Population newpop, int subpopulation, int thread)
          Returns true if this BreedingSource, when attached to the given subpopulation, will produce individuals of the subpopulation's species.
 java.lang.Object protoClone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 void setup(EvolutionState state, Parameter base)
          Sets up the BreedingPipeline.
 
Methods inherited from class ec.BreedingSource
getProbability, pickRandom, produce, protoCloneSimple, setProbability, setupProbabilities, typicalIndsProduced
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

V_SAME

public static final java.lang.String V_SAME
Indicates that a source is the exact same source as the previous source.

DYNAMIC_SOURCES

public static final int DYNAMIC_SOURCES
Indicates that the number of sources is variable and determined by the user in the parameter file.

P_NUMSOURCES

public static final java.lang.String P_NUMSOURCES
Standard parameter for number of sources (only used if numSources returns DYNAMIC_SOURCES

P_SOURCE

public static final java.lang.String P_SOURCE
Standard parameter for individual-selectors associated with a BreedingPipeline

sources

public BreedingSource[] sources
Array of sources feeding the pipeline
Constructor Detail

BreedingPipeline

public BreedingPipeline()
Method Detail

numSources

public abstract int numSources()
Returns the number of sources to this pipeline. Called during BreedingPipeline's setup. Be sure to return a value > 0, or DYNAMIC_SOURCES which indicates that setup should check the parameter file for the parameter "num-sources" to make its determination.

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from class: BreedingSource
Sets up the BreedingPipeline. You can use state.output.error here because the top-level caller promises to call exitIfErrors() after calling setup. Note that probability might get modified again by an external source if it doesn't normalize right.

The most common modification is to normalize it with some other set of probabilities, then set all of them up in increasing summation; this allows the use of the fast static BreedingSource-picking utility method, BreedingSource.pickRandom(...). In order to use this method, for example, if four breeding source probabilities are {0.3, 0.2, 0.1, 0.4}, then they should get normalized and summed by the outside owners as: {0.3, 0.5, 0.6, 1.0}.

Overrides:
setup in class BreedingSource
Tags copied from class: BreedingSource
See Also:
Prototype.setup(EvolutionState,Parameter)

protoClone

public java.lang.Object protoClone()
                            throws java.lang.CloneNotSupportedException
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.

Overrides:
protoClone in class BreedingSource

produces

public boolean produces(EvolutionState state,
                        Population newpop,
                        int subpopulation,
                        int thread)
Description copied from class: BreedingSource
Returns true if this BreedingSource, when attached to the given subpopulation, will produce individuals of the subpopulation's species. SelectionMethods should additionally make sure that their Fitnesses are of a valid type, if necessary. newpop *may* be the same as state.population
Overrides:
produces in class BreedingSource

prepareToProduce

public void prepareToProduce(EvolutionState state,
                             int subpopulation,
                             int thread)
Description copied from class: BreedingSource
Called before produce(...), usually once a generation, or maybe only once if you're doing steady-state evolution, to let the breeding source "warm up" prior to producing. Individuals should be produced from old individuals in positions [start...start+length] in the subpopulation only. May be called again to reset the BreedingSource for a whole 'nuther subpopulation.
Overrides:
prepareToProduce in class BreedingSource

preparePipeline

public void preparePipeline(java.lang.Object hook)
Description copied from class: BreedingSource
A hook which should be passed to all your subsidiary breeding sources. If you are a BreedingPipeline and you implement your sources in a way different than using the sources[] array, be sure to override this method so that it calls preparePipeline(hook) on all of your sources. This method might get called more than once, and by various objects as needed. If you use it, you should determine somehow how to use it to send information under the assumption that it might be sent by nested items in the pipeline; you don't want to scribble over each other's calls! Note that this method should travel *all* breeding source paths regardless of whether or not it's redundant to do so.
Overrides:
preparePipeline in class BreedingSource