private static void GenerateTestResults() { var referencePareto = LoadReferencePareto(); NsgaHelper.AssignCrowdingDistances(referencePareto.ResultPoints); var filteredIndividuals = referencePareto.ResultPoints.OrderByDescending(i => i.CrowdingDistance).Take(150).ToList(); var nadir = FindNadir(filteredIndividuals); var referenceParetoHyperVolume = RInvoker.HyperVolume(filteredIndividuals, nadir); var results = LoadResults(OutputsDirectory); var counter = 0; var counterMax = results.Count; foreach (var result in results) { try { result.HyperVolume = referenceParetoHyperVolume - RInvoker.HyperVolume(result.ResultPoints, nadir); result.EpsilonIndicator = RInvoker.Epsilon(result.ResultPoints, referencePareto.ResultPoints); } catch (Exception e) { Console.WriteLine("error in caling R script\n " + e.Message); } counter++; Console.WriteLine($"{counter}/{counterMax}"); } WriteToCsv(OutputsDirectory, results); SaveAverageValues(results); Console.WriteLine("done"); }
public List <GroupDietIndividual> TopsisSort(List <GroupDietIndividual> individuals, List <WeightsModel> topisModels) { var macroMin = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.Macro).Score).Min(); var prepTimeMin = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.PreparationTime).Score).Min(); var costMin = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.Cost).Score).Min(); var preferencesMin = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.Preferences).Score).Min(); var macroMax = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.Macro).Score).Max(); var prepTimeMax = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.PreparationTime).Score).Max(); var costMax = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.Cost).Score).Max(); var preferencesMax = individuals.Select(i => i.Evaluations.Single(e => e.Type == ObjectiveType.Preferences).Score).Max(); var normalized = individuals.Select(i => new GroupDietIndividual(new GroupDiet()) { Evaluations = new List <Evaluation> { Normalize(i.Evaluations.Single(e => e.Type == ObjectiveType.Macro), macroMin, macroMax), Normalize(i.Evaluations.Single(e => e.Type == ObjectiveType.PreparationTime), prepTimeMin, prepTimeMax), Normalize(i.Evaluations.Single(e => e.Type == ObjectiveType.Cost), costMin, costMax), Normalize(i.Evaluations.Single(e => e.Type == ObjectiveType.Preferences), preferencesMin, preferencesMax) }, Rank = individuals.IndexOf(i) }); var averageTopsis = MakeAverage(topisModels); var result = RInvoker.Topsis(normalized.ToList(), averageTopsis.CostWeight, averageTopsis.PreferncesWeight, averageTopsis.PreparationTimeWeight, averageTopsis.MacroWeight); return(result.Select(i => individuals[i.Rank]).ToList()); }
private static void SaveAverageValues(List <FrontResult> results) { var groupped = results.GroupBy( r => r.PopulationSize.ToString(CultureInfo.InvariantCulture) + "_" + r.Iterations.ToString(CultureInfo.InvariantCulture) + "_" + r.MutationProbability.ToString(CultureInfo.InvariantCulture)).ToList(); var csv = new StringBuilder(); csv.AppendLine("Iterations;MutationProbability;PopulationSize;Time;pvalue;w;HyperVolume;pvalue;w;Epsilon;pvalue;w"); foreach (var group in groupped) { var hvs = group.Select(i => i.HyperVolume).ToList(); var times = group.Select(i => i.Time).ToList(); var epsolons = group.Select(i => i.EpsilonIndicator).ToList(); var avg = new AverageResult(); if (hvs.Count > 3 && hvs.Any(value => value > 0)) { avg.NormalityHv = RInvoker.Shapiro(hvs); } if (times.Count > 3 && hvs.Any(value => value > 0)) { avg.NormalityTime = RInvoker.Shapiro(times); } if (epsolons.Count > 3 && epsolons.Any(value => value > 0)) { avg.NormalityEpsilon = RInvoker.Shapiro(epsolons); } avg.Hypervolume = group.Select(i => i.HyperVolume).Average(); avg.Time = group.Select(i => i.Time).Average(); avg.Epsilon = group.Select(i => i.EpsilonIndicator).Average(); csv.AppendLine( $"{group.First().Iterations};{group.First().MutationProbability};{group.First().PopulationSize};{avg.Time};{avg.NormalityTime.Pvalue};{avg.NormalityTime.Statistic};{avg.Hypervolume};{avg.NormalityHv.Pvalue};{avg.NormalityHv.Statistic};{avg.Epsilon};{avg.NormalityEpsilon.Pvalue};{avg.NormalityEpsilon.Statistic}"); } var filesInOutputDir = Directory.GetFiles(OutputsDirectory); var fileIndex = 0; var fileName = "averageResults.csv"; while (filesInOutputDir.Any(path => path.EndsWith(fileName))) { fileIndex++; fileName = $"averageResults_{fileIndex}.csv"; } File.WriteAllText($"{OutputsDirectory}\\{fileName}", csv.ToString()); }
private static void TestMethod() { var results = LoadResults(OutputsDirectory); var referencePareto = LoadReferencePareto(); var epsilons = new List <double>(); foreach (var result in results) { var eps = RInvoker.Epsilon(result.ResultPoints, referencePareto.ResultPoints); epsilons.Add(eps); } Console.ReadLine(); }