private void Button_Click_2(object sender, RoutedEventArgs e) { FileRead read = new FileRead(); read.fileread(); Problem problem = read.GetProblem(); Algorithm algorithm = read.GetAlgorithm(); QualityIndicator indicators = new QualityIndicator(problem, read.Qi); NewAlgorithmTest test = new NewAlgorithmTest(); for (int i = 1; i <= int.Parse(read.Rt); i++) { // Logger object and file to store log messages var logger = Logger.Log; var appenders = logger.Logger.Repository.GetAppenders(); var fileAppender = appenders[0] as log4net.Appender.FileAppender; fileAppender.File = read.DirPath + "/" + read.Al + i + ".log"; fileAppender.ActivateOptions(); string filevar = read.DirPath + "/VAR" + i; string filefun = read.DirPath + "/FUN" + i; FileStream file = new FileStream(read.DirPath + "/MOEADnew" + i + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter newlogger = new StreamWriter(file); // Execute the Algorithm long initTime = Environment.TickCount; SolutionSet population = test.Mix(); long estimatedTime = Environment.TickCount - initTime; // Result messages logger.Info("Total execution time: " + estimatedTime + "ms"); logger.Info("Variables values have been writen to file " + filevar); newlogger.WriteLine("Total execution time: " + estimatedTime + "ms" + "\n"); newlogger.WriteLine("Variables values have been writen to file " + filevar + "\n"); population.PrintVariablesToFile(filevar); logger.Info("Objectives values have been writen to file " + filefun); population.PrintObjectivesToFile(filefun); Console.WriteLine("Time: " + estimatedTime); newlogger.WriteLine("Time: " + estimatedTime + "\n"); Console.ReadLine(); if (indicators != null) { logger.Info("Quality indicators"); logger.Info("Hypervolume: " + indicators.GetHypervolume(population)); logger.Info("GD : " + indicators.GetGD(population)); logger.Info("IGD : " + indicators.GetIGD(population)); logger.Info("Spread : " + indicators.GetSpread(population)); logger.Info("Epsilon : " + indicators.GetEpsilon(population)); newlogger.WriteLine("Quality indicators"); newlogger.WriteLine("Hypervolume: " + indicators.GetHypervolume(population).ToString("F18") + "\n"); newlogger.WriteLine("GD : " + indicators.GetGD(population).ToString("F18") + "\n"); newlogger.WriteLine("IGD : " + indicators.GetIGD(population).ToString("F18") + "\n"); newlogger.WriteLine("Spread : " + indicators.GetSpread(population).ToString("F18") + "\n"); newlogger.WriteLine("Epsilon : " + indicators.GetEpsilon(population).ToString("F18") + "\n"); int evaluations = test.GetEvaluations(); logger.Info("Speed : " + evaluations + " evaluations"); newlogger.WriteLine("Speed : " + evaluations + " evaluations" + "\n"); } newlogger.Close(); file.Close(); } }
public void MyAlgorithm() { Problem problem = null; // The problem to solve Algorithm algorithm = null; // The algorithm to use Operator crossover = null; // Crossover operator Operator mutation = null; // Mutation operator Operator selection = null; // Selection operator QualityIndicator indicators; // Object to get quality indicators FileRead fileRead = new FileRead(); fileRead.fileread(); problem = fileRead.GetProblem(); algorithm = fileRead.GetAlgorithm(); //crossover = fileRead.GetCrossover(); mutation = fileRead.GetMutation(); selection = fileRead.GetSelection(); // Quality Indicators Operator //indicators = new QualityIndicator(problem, "DTLZ1.3D.pf"); indicators = new QualityIndicator(problem, fileRead.Qi); //indicators = new QualityIndicator(problem, "LZ09_F1.pf"); // Add the operators to the algorithm algorithm.AddOperator("crossover", crossover); algorithm.AddOperator("mutation", mutation); algorithm.AddOperator("selection", selection); // Add the indicator object to the algorithm algorithm.SetInputParameter("indicators", indicators); for (int i = 1; i <= int.Parse(fileRead.Rt); i++) { // Logger object and file to store log messages var logger = Logger.Log; var appenders = logger.Logger.Repository.GetAppenders(); var fileAppender = appenders[0] as log4net.Appender.FileAppender; fileAppender.File = fileRead.DirPath + "/" + fileRead.Al + i + ".log"; fileAppender.ActivateOptions(); string filevar = fileRead.DirPath + "/VAR" + i; string filefun = fileRead.DirPath + "/FUN" + i; FileStream file = new FileStream(fileRead.DirPath + "/" + fileRead.Al + "new" + i + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter newlogger = new StreamWriter(file); // Execute the Algorithm long initTime = Environment.TickCount; SolutionSet population = algorithm.Execute(); long estimatedTime = Environment.TickCount - initTime; // Result messages logger.Info("Total execution time: " + estimatedTime + "ms"); logger.Info("Variables values have been writen to file " + filevar); newlogger.WriteLine("Total execution time: " + estimatedTime + "ms" + "\n"); newlogger.WriteLine("Variables values have been writen to file " + filevar + "\n"); population.PrintVariablesToFile(filevar); logger.Info("Objectives values have been writen to file " + filefun); population.PrintObjectivesToFile(filefun); Console.WriteLine("Time: " + estimatedTime); newlogger.WriteLine("Time: " + estimatedTime + "\n"); Console.ReadLine(); if (indicators != null) { logger.Info("Quality indicators"); logger.Info("Hypervolume: " + indicators.GetHypervolume(population)); logger.Info("GD : " + indicators.GetGD(population)); logger.Info("IGD : " + indicators.GetIGD(population)); logger.Info("Spread : " + indicators.GetSpread(population)); logger.Info("Epsilon : " + indicators.GetEpsilon(population)); newlogger.WriteLine("Quality indicators"); newlogger.WriteLine("Hypervolume: " + indicators.GetHypervolume(population).ToString("F18") + "\n"); newlogger.WriteLine("GD : " + indicators.GetGD(population).ToString("F18") + "\n"); newlogger.WriteLine("IGD : " + indicators.GetIGD(population).ToString("F18") + "\n"); newlogger.WriteLine("Spread : " + indicators.GetSpread(population).ToString("F18") + "\n"); newlogger.WriteLine("Epsilon : " + indicators.GetEpsilon(population).ToString("F18") + "\n"); int evaluations = (int)algorithm.GetOutputParameter("evaluations"); logger.Info("Speed : " + evaluations + " evaluations"); newlogger.WriteLine("Speed : " + evaluations + " evaluations" + "\n"); } newlogger.Close(); file.Close(); algorithm.AddOperator("mutation", mutation); } }