/* Copyright 2006 by Sean Luke Licensed under the Academic Free License version 3.0 See the file "LICENSE" for more information */ package ec.breed; import ec.*; import ec.util.*; /* * MultiBreedingPipeline.java * * Created: December 28, 1999 * By: Sean Luke */ /** * MultiBreedingPipeline is a BreedingPipeline stores some n child sources; * each time it must produce an individual or two, * it picks one of these sources at random and has it do the production.

Typical Number of Individuals Produced Per produce(...) call
If by base.generate-max is true, then always the maximum number of the typical numbers of any child source. If false, then varies depending on the child source picked.

Number of Sources
Dynamic. As many as the user specifies.

Parameters
base.generate-max
bool = true (default) or false
(Each time produce(...) is called, should the MultiBreedingPipeline force all its sources to produce exactly the same number of individuals as the largest typical number of individuals produced by any source in the group?)

Default Base
breed.multibreed * * @author Sean Luke * @version 1.0 */ public class MultiBreedingPipeline extends BreedingPipeline { public static final String P_GEN_MAX = "generate-max"; public static final String P_MULTIBREED = "multibreed"; public int maxGeneratable; public boolean generateMax; public Parameter defaultBase() { return BreedDefaults.base().push(P_MULTIBREED); } public int numSources() { return DYNAMIC_SOURCES; } public void setup(final EvolutionState state, final Parameter base) { super.setup(state,base); Parameter def = defaultBase(); float total = 0.0f; for(int x=0;x= 0.0",base); // convenient that NO_PROBABILITY is -1... else total += sources[x].probability; } state.output.exitIfErrors(); // Now check for nonzero probability (we know it's positive) if (total == 0.0) state.output.warning("MultiBreedingPipeline's children have all zero probabilities -- this will be treated as a uniform distribution. This could be an error.", base); // allow all zero probabilities BreedingSource.setupProbabilities(sources); generateMax = state.parameters.getBoolean(base.push(P_GEN_MAX),def.push(P_GEN_MAX),true); maxGeneratable=0; // indicates that I don't know what it is yet. // declare that likelihood isn't used if (likelihood < 1.0f) state.output.warning("MultiBreedingPipeline does not respond to the 'likelihood' parameter.", base.push(P_LIKELIHOOD), def.push(P_LIKELIHOOD)); } /** Returns the max of typicalIndsProduced() of all its children */ public int typicalIndsProduced() { if (maxGeneratable==0) // not determined yet maxGeneratable = maxChildProduction(); return maxGeneratable; } public int produce(final int min, final int max, final int start, final int subpopulation, final Individual[] inds, final EvolutionState state, final int thread) { BreedingSource s = sources[BreedingSource.pickRandom( sources,state.random[thread].nextFloat())]; int total; if (generateMax) { if (maxGeneratable==0) maxGeneratable = maxChildProduction(); int n = maxGeneratable; if (n < min) n = min; if (n > max) n = max; total = s.produce( n,n,start,subpopulation,inds,state,thread); } else { total = s.produce( min,max,start,subpopulation,inds,state,thread); } // clone if necessary if (s instanceof SelectionMethod) for(int q=start; q < total+start; q++) inds[q] = (Individual)(inds[q].clone()); return total; } }