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); } }
private static void SimulatedAnnealingTtp1(Problem.Problem problem, string algorithmSrcFilePath, string outputFilePath, string logOutputType) { var algorithmParams = Loader.Loader.LoadAnnealingTtp1Params(algorithmSrcFilePath); if (algorithmParams == null) { Console.WriteLine("Error reading annealing ttp1's configuration src file."); return; } Console.WriteLine("Done reading annealing ttp1's configuration src file."); var logger = new Logger.Logger(outputFilePath, logOutputType); try { logger.LogAnnealingTtp1Intro(algorithmParams); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine("Error writing to annealing ttp1's log output file."); return; } var algorithm = new AnnealingTtp1(problem, algorithmParams); void logAnnealingCycle(int annealingCycle, double globalBestFitness, double bestFitness, double currentFitness) { logger.LogGeneticThenSaTtp1(annealingCycle, globalBestFitness, null, null, bestFitness, currentFitness); } void logOutro(List <double> bestFitnesses) { logger.LogOutro(bestFitnesses); } algorithm.Execute(logAnnealingCycle, logOutro); }