コード例 #1
0
        public void Execute(Logger.Logger logger)
        {
            void logGeneration(int generation, double bestFitness, double averageFitness, double worstFitness)
            {
                logger.LogGeneticThenSaTtp1(generation, bestFitness, averageFitness, worstFitness, null, null);
            }

            void logOutro(List <double> bestFitnesses)
            {
                logger.LogOutro(bestFitnesses);
            }

            var finalPopulations = Genetic.Execute(logGeneration, logOutro);

            void logAnnealingCycle(int annealingCycle, double globalBestFitness, double bestFitness, double currentFitness)
            {
                logger.LogGeneticThenSaTtp1(annealingCycle, globalBestFitness, null, null, bestFitness, currentFitness);
            }

            foreach (var population in finalPopulations)
            {
                var         bestFitness = double.MinValue;
                IIndividual bestIndiv   = null;
                population.ForEach(indiv =>
                {
                    var fitness = Problem.Fitness(indiv);
                    if (fitness > bestFitness)
                    {
                        bestFitness = fitness;
                        bestIndiv   = indiv;
                    }
                });

                if (bestIndiv == null)
                {
                    continue;
                }

                Annealing.Execute(logAnnealingCycle, logOutro, bestIndiv, Parameters.GeneticParameters.NumGenerations);
            }
        }