protected override void Evolve(EvaluatorBase evaluator) { var offspringPopulationSize = Parameters.OffspringPopulationSize; var numberOfParentsSolutionsToSelect = Parameters.NumberOfParentsSolutionsToSelect; for (var i = 0; i < offspringPopulationSize; i++) { var parentsPopulation = new Solution[numberOfParentsSolutionsToSelect]; for (var j = 0; j < numberOfParentsSolutionsToSelect; j++) { parentsPopulation[j] = ParentsSelector.Select(BasePopulation); } OffspringPopulation[i] = StdDeviationsRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]); OffspringPopulation[i] = RotationsRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]); OffspringPopulation[i] = ObjectRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]); OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]); } BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation); }
public void Mutate() { var watch = new Stopwatch(); watch.Start(); _mutator.Mutate(Population, MaxFitness); watch.Stop(); _performanceCounters[CounterType.Mutate] = watch.Elapsed; }
//HACKS TODO protected override void Evolve(EvaluatorBase evaluator) { var offspringPopulationSize = Parameters.OffspringPopulationSize; //var stdDevsMutationTime = TimeSpan.Zero; //var rotationsMutationTime = TimeSpan.Zero; //var objectMutationTime = TimeSpan.Zero; //var evaluationTime = TimeSpan.Zero; //var stoper = new Stopwatch(); for (var i = 0; i < offspringPopulationSize; i++) { OffspringPopulation[i] = ParentsSelector.Select(BasePopulation); if (Parameters.TrackEvolutionSteps) { CurrentMutation = new MutationStep(ParentsSelector.LastSelectedParentIndex, OffspringPopulation[i]); } //stoper.Restart(); OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //stdDevsMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //rotationsMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //objectMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]); //stoper.Stop(); //evaluationTime += stoper.Elapsed; if (Parameters.TrackEvolutionSteps) { CurrentMutation.Offspring = OffspringPopulation[i].DeepCopyByExpressionTree(); CurrentEvolutionStep.Mutations.Add(CurrentMutation); } } //stoper.Restart(); BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation); //stoper.Stop(); //Statistics.MeanSurvivorsSelectionTime += stoper.Elapsed; //Statistics.MeanStdDevsMutationTime += TimeSpan.FromTicks(stdDevsMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanRotationsMutationTime += TimeSpan.FromTicks(rotationsMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanObjectMutationTime += TimeSpan.FromTicks(objectMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanEvaluationTime += TimeSpan.FromTicks(evaluationTime.Ticks / offspringPopulationSize); if (Parameters.TrackEvolutionSteps) { CurrentEvolutionStep.NewPopulation = BasePopulation.DeepCopyByExpressionTree(); } }