SimpleBreeder extends Breeder { public void setup(final EvolutionState state, final Parameter base) { Parameter p = new Parameter(Initializer.P_POP).push(Population.P_SIZE); int size = state.parameters.getInt(p,null,1); eliteFrac = new double[size]; elite = new int[size]; for(int i = 0; i < size; i++) eliteFrac[i] = elite[i] = NOT_SET; reevaluateElites = new boolean[size]; sequentialBreeding = state.parameters.getBoolean(base.push(P_SEQUENTIAL_BREEDING), null, false); if (sequentialBreeding && (size == 1)) state.output.fatal("The Breeder is breeding sequentially, but you have only one population.", base.push(P_SEQUENTIAL_BREEDING)); clonePipelineAndPopulation =state.parameters.getBoolean(base.push(P_CLONE_PIPELINE_AND_POPULATION), null, true); if (!clonePipelineAndPopulation && (state.breedthreads > 1)) state.output.fatal("The Breeder is not cloning its pipeline and population, but you have more than one thread.", base.push(P_CLONE_PIPELINE_AND_POPULATION)); int defaultSubpop = state.parameters.getInt(new Parameter(Initializer.P_POP).push(Population.P_DEFAULT_SUBPOP), null, 0); for(int x=0;x<size;x++) { if (state.parameters.exists(base.push(P_ELITE).push(""+x),null)) { if (state.parameters.exists(base.push(P_ELITE_FRAC).push(""+x),null)) state.output.error("Both elite and elite-frac specified for subpouplation " + x + ".", base.push(P_ELITE_FRAC).push(""+x), base.push(P_ELITE_FRAC).push(""+x)); else { elite[x] = state.parameters.getIntWithDefault(base.push(P_ELITE).push(""+x),null,0); if (elite[x] < 0) state.output.error("Elites for subpopulation " + x + " must be an integer >= 0", base.push(P_ELITE).push(""+x)); } } else if (state.parameters.exists(base.push(P_ELITE_FRAC).push(""+x),null)) { eliteFrac[x] = state.parameters.getDoubleWithMax(base.push(P_ELITE_FRAC).push(""+x),null,0.0, 1.0); if (eliteFrac[x] < 0.0) state.output.error("Elite Fraction of subpopulation " + x + " must be a real value between 0.0 and 1.0 inclusive", base.push(P_ELITE_FRAC).push(""+x)); } else if (defaultSubpop >= 0) { if (state.parameters.exists(base.push(P_ELITE).push(""+defaultSubpop),null)) { elite[x] = state.parameters.getIntWithDefault(base.push(P_ELITE).push(""+defaultSubpop),null,0); if (elite[x] < 0) state.output.warning("Invalid default subpopulation elite value."); } else if (state.parameters.exists(base.push(P_ELITE_FRAC).push(""+defaultSubpop),null)) { eliteFrac[x] = state.parameters.getDoubleWithMax(base.push(P_ELITE_FRAC).push(""+defaultSubpop),null,0.0, 1.0); if (eliteFrac[x] < 0.0) state.output.warning("Invalid default subpopulation elite-frac value."); } else { elite[x] = 0; } } else { elite[x] = 0; } if (defaultSubpop >= 0 && !state.parameters.exists(base.push(P_REEVALUATE_ELITES).push(""+x),null)) { reevaluateElites[x] = state.parameters.getBoolean(base.push(P_REEVALUATE_ELITES).push(""+defaultSubpop), null, false); if (reevaluateElites[x]) state.output.warning("Elite reevaluation not specified for subpopulation " + x + ". Using values for default subpopulation " + defaultSubpop + ": " + reevaluateElites[x]); } else { reevaluateElites[x] = state.parameters.getBoolean(base.push(P_REEVALUATE_ELITES).push(""+x), null, false); } } state.output.exitIfErrors(); }  boolean usingElitism(int subpopulation); int numElites(EvolutionState state, int subpopulation); void setup(final EvolutionState state, final Parameter base); Population breedPopulation(EvolutionState state); void postProcess(EvolutionState state); boolean shouldBreedSubpop(EvolutionState state, int subpop, int threadnum); static final String P_ELITE; static final String P_ELITE_FRAC; static final String P_REEVALUATE_ELITES; static final String P_SEQUENTIAL_BREEDING; static final String P_CLONE_PIPELINE_AND_POPULATION; public int[] elite; public double[] eliteFrac; public boolean[] reevaluateElites; public boolean sequentialBreeding; public boolean clonePipelineAndPopulation; public Population backupPopulation; public ArrayList<Individual> newIndividuals; static final int NOT_SET; public ThreadPool pool; }
@Test public void testSetup() { SimpleBreeder instance = new SimpleBreeder(); instance.setup(state, BASE); }