Package ec

Class BreedingPipeline

java.lang.Object
ec.BreedingSource
ec.BreedingPipeline
All Implemented Interfaces:
Prototype, Setup, SteadyStateBSourceForm, RandomChoiceChooserD, Serializable, Cloneable
Direct Known Subclasses:
BufferedBreedingPipeline, CheckingPipeline, FirstCopyPipeline, ForceBreedingPipeline, GeneDuplicationPipeline, GenerationSwitchPipeline, GPBreedingPipeline, InitializationPipeline, ListCrossoverPipeline, MultiBreedingPipeline, MultipleVectorCrossoverPipeline, RepeatPipeline, ReproductionPipeline, RuleCrossoverPipeline, RuleMutationPipeline, UniquePipeline, VectorCrossoverPipeline, VectorMutationPipeline

public abstract class BreedingPipeline extends BreedingSource implements SteadyStateBSourceForm
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.

A BreedingPipeline implements SteadyStateBSourceForm, meaning that it receives the individualReplaced(...) and sourcesAreProperForm(...) messages. however by default it doesn't do anything with these except distribute them to its sources. You might override these to do something more interesting.

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, or the value stub
(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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Indicates that the number of sources is not hard coded but is determined by the user in the parameter file.
    double
     
    My parameter base -- I keep it around so I can print some messages that are useful with it (not deep cloned)
    static final String
    Indicates the probability that the Breeding Pipeline will perform its mutative action instead of just doing reproduction.
    static final String
    Standard parameter for number of sources (only used if numSources returns DYNAMIC_SOURCES)
    static final String
    Standard parameter for individual-selectors associated with a BreedingPipeline
    Array of sources feeding the pipeline
    static final String
    Indicates that a source is the exact same source as the previous source.
    static final String
    Indicates that the source will be filled later via a call to setStubs().

    Fields inherited from class ec.BreedingSource

    NO_PROBABILITY, P_PROB, probability
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
    void
     
    void
    finishProducing(EvolutionState state, int subpopulation, int thread)
    Called after produce(...), usually once a generation, or maybe only once if you're doing steady-state evolution (at the end of the run).
    void
    individualReplaced(SteadyStateEvolutionState state, int subpopulation, int thread, int individual)
    Called whenever an individual has been replaced by another in the population.
    int
    Returns the maximum among the typicalIndsProduced() for any children -- a function that's useful internally, not very useful for you to call externally.
    int
    Returns the minimum among the typicalIndsProduced() for any children -- a function that's useful internally, not very useful for you to call externally.
    abstract int
    Returns the number of sources to this pipeline.
    void
    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.
    void
    Sets up the BreedingPipeline.
    void
    Issue an error (not a fatal -- we guarantee that callers of this method will also call exitIfErrors) if any of your sources, or their sources, etc., are not of SteadyStateBSourceForm.
    int
    Returns the "typical" number of individuals produced -- by default this is the minimum typical number of individuals produced by any children sources of the pipeline.

    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 Details

    • V_SAME

      public static final String V_SAME
      Indicates that a source is the exact same source as the previous source.
      See Also:
    • V_STUB

      public static final String V_STUB
      Indicates that the source will be filled later via a call to setStubs().
      See Also:
    • P_LIKELIHOOD

      public static final String P_LIKELIHOOD
      Indicates the probability that the Breeding Pipeline will perform its mutative action instead of just doing reproduction.
      See Also:
    • DYNAMIC_SOURCES

      public static final int DYNAMIC_SOURCES
      Indicates that the number of sources is not hard coded but is determined by the user in the parameter file.
      See Also:
    • P_NUMSOURCES

      public static final String P_NUMSOURCES
      Standard parameter for number of sources (only used if numSources returns DYNAMIC_SOURCES)
      See Also:
    • P_SOURCE

      public static final String P_SOURCE
      Standard parameter for individual-selectors associated with a BreedingPipeline
      See Also:
    • mybase

      public Parameter mybase
      My parameter base -- I keep it around so I can print some messages that are useful with it (not deep cloned)
    • likelihood

      public double likelihood
    • sources

      public BreedingSource[] sources
      Array of sources feeding the pipeline
  • Constructor Details

    • BreedingPipeline

      public BreedingPipeline()
  • Method Details

    • 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.
    • minChildProduction

      public int minChildProduction()
      Returns the minimum among the typicalIndsProduced() for any children -- a function that's useful internally, not very useful for you to call externally.
    • maxChildProduction

      public int maxChildProduction()
      Returns the maximum among the typicalIndsProduced() for any children -- a function that's useful internally, not very useful for you to call externally.
    • fillStubs

      public void fillStubs(EvolutionState state, BreedingSource source)
      Overrides:
      fillStubs in class BreedingSource
    • typicalIndsProduced

      public int typicalIndsProduced()
      Returns the "typical" number of individuals produced -- by default this is the minimum typical number of individuals produced by any children sources of the pipeline. If you'd prefer something different, override this method.
      Specified by:
      typicalIndsProduced in class BreedingSource
    • 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}.

      Specified by:
      setup in interface Prototype
      Specified by:
      setup in interface Setup
      Overrides:
      setup in class BreedingSource
      See Also:
    • clone

      public 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.

      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:

      • If you hold objects which are shared with other instances, don't clone them.
      • If you hold objects which must be unique, clone them.
      • If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
      • DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
      • Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.

      Implementations.

      • If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
      • If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are not abstract, then you should implement it as follows:

         public Object clone() 
             {
             try
                 { 
                 return super.clone();
                 }
             catch ((CloneNotSupportedException e)
                 { throw new InternalError(); } // never happens
             }
                
      • If no ancestor of yours implements clone(), but you need to deep-clone some things, then you should implement it as follows:

         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;
             } 
                
      • If an ancestor has implemented clone(), and you also need to deep clone some things, then you should implement it as follows:

         public Object clone() 
             { 
             MyObject myobj = (MyObject) (super.clone());
        
             // put your deep-cloning code here...
        
             return myobj;
             } 
                
      Specified by:
      clone in interface Prototype
      Overrides:
      clone 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
      Specified by:
      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.
      Specified by:
      prepareToProduce in class BreedingSource
    • finishProducing

      public void finishProducing(EvolutionState state, int subpopulation, int thread)
      Description copied from class: BreedingSource
      Called after produce(...), usually once a generation, or maybe only once if you're doing steady-state evolution (at the end of the run).
      Specified by:
      finishProducing in class BreedingSource
    • preparePipeline

      public void preparePipeline(Object hook)
      Description copied from class: BreedingSource
      A hook which should be passed to all your subsidiary breeding sources. The default does this for you already, so ordinarily you don't need to change anything. 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.

      ECJ at present does not custom-implement or call this method: it's available for you. Becuase it has custom functionality, 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
    • individualReplaced

      public void individualReplaced(SteadyStateEvolutionState state, int subpopulation, int thread, int individual)
      Description copied from interface: SteadyStateBSourceForm
      Called whenever an individual has been replaced by another in the population.
      Specified by:
      individualReplaced in interface SteadyStateBSourceForm
    • sourcesAreProperForm

      public void sourcesAreProperForm(SteadyStateEvolutionState state)
      Description copied from interface: SteadyStateBSourceForm
      Issue an error (not a fatal -- we guarantee that callers of this method will also call exitIfErrors) if any of your sources, or their sources, etc., are not of SteadyStateBSourceForm.
      Specified by:
      sourcesAreProperForm in interface SteadyStateBSourceForm