/// <summary> /// A private helper function for evaluatePopulation which evaluates a chunk /// of individuals in a subpop for a given thread. /// Although this method is declared /// protected, you should not call it. /// </summary> protected virtual void EvalPopChunk(IEvolutionState state, int[] numinds, int[] from, int threadnum, ISimpleProblem p) { p.PrepareToEvaluate(state, threadnum); var subpops = state.Population.Subpops; var len = subpops.Count; for (var pop = 0; pop < len; pop++) { // start evaluatin'! var fp = from[pop]; var upperbound = fp + numinds[pop]; var inds = subpops[pop].Individuals; for (var x = fp; x < upperbound; x++) { p.Evaluate(state, inds[x], pop, threadnum); } state.IncrementEvaluations(upperbound - fp); } p.FinishEvaluating(state, threadnum); }
public override void EvaluatePopulation(IEvolutionState state) { // determine who needs to be evaluated var preAssessFitness = new bool[state.Population.Subpops.Count]; var postAssessFitness = new bool[state.Population.Subpops.Count]; for (var i = 0; i < state.Population.Subpops.Count; i++) { postAssessFitness[i] = ShouldEvaluateSubpop(state, i, 0); preAssessFitness[i] = postAssessFitness[i] || (state.Generation == 0); // always prepare (set up trials) on generation 0 } // do evaluation BeforeCoevolutionaryEvaluation(state, state.Population, (IGroupedProblem)p_problem); ((IGroupedProblem)p_problem).PreprocessPopulation(state, state.Population, preAssessFitness, false); PerformCoevolutionaryEvaluation(state, state.Population, (IGroupedProblem)p_problem); state.IncrementEvaluations(((IGroupedProblem)p_problem).PostprocessPopulation(state, state.Population, postAssessFitness, false)); AfterCoevolutionaryEvaluation(state, state.Population, (IGroupedProblem)p_problem); }