private void GenerateReferenceParetoFronts() { var problems = experiment.ExperimentProblems; var referencePath = Path.Combine(experiment.ExperimentBaseDirectory, "ReferenceParetoFront"); if (!Directory.Exists(referencePath)) { Directory.CreateDirectory(referencePath); } foreach (var problem in problems) { if (string.IsNullOrEmpty(problem.ParetoFront)) { NonDominatedSolutionList solutionSet = new NonDominatedSolutionList(); string file = Path.Combine(referencePath, problem.Alias + ".pf"); MetricsUtil metrics = new MetricsUtil(); foreach (var algorithmDictionary in problem.AlgorithmDictionary) { foreach (var algorithm in algorithmDictionary.Value) { metrics.ReadNonDominatedSolutionSet(algorithm.Result.GetObjectives(), solutionSet); } } solutionSet.PrintObjectivesToFile(file); problem.ParetoFront = file; } } }
/// <summary> /// Reads a set of non dominated solutions from a file and store it in a /// existing non dominated solution set /// </summary> /// <param name="path">The path of the file containing the data</param> /// <param name="solutionSet">A solution set</param> public void ReadNonDominatedSolutionSet(string path, NonDominatedSolutionList solutionSet) { try { /* Open the file */ using (StreamReader reader = new StreamReader(path)) { string aux = reader.ReadLine(); while (aux != null) { string[] st = aux.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); int i = 0; Solution solution = new Solution(st.Length); foreach (string s in st) { double value = JMetalCSharp.Utils.Utils.ParseDoubleInvariant(s); solution.Objective[i] = value; i++; } solutionSet.Add(solution); aux = reader.ReadLine(); } } } catch (Exception e) { Console.WriteLine("ReadNonDominatedSolutionSet: " + path); Console.WriteLine(e.StackTrace); } }
/// <summary> /// Reads a set of non dominated solutions from a file /// </summary> /// <param name="path">The path of the file containing the data</param> /// <returns>A solution set</returns> public SolutionSet ReadNonDominatedSolutionSet(string name) { var path = Path.GetFullPath("./Data/ParetoFronts/" + name); try { SolutionSet solutionSet = new NonDominatedSolutionList(); using (StreamReader reader = new StreamReader(path)) { string aux = reader.ReadLine(); while (aux != null) { string[] st = aux.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); int i = 0; Solution solution = new Solution(st.Length); foreach (string s in st) { double value = JMetalCSharp.Utils.Utils.ParseDoubleInvariant(s); solution.Objective[i] = value; i++; } solutionSet.Add(solution); aux = reader.ReadLine(); } } return(solutionSet); } catch (Exception e) { Console.WriteLine("ReadNonDominatedSolutionSet: " + path); Console.WriteLine(e.StackTrace); } return(null); }
public void ReadNonDominatedSolutionSet(double[][] objectives, NonDominatedSolutionList solutionSet) { double[] solutionObjectives; for (int i = 0, li = objectives.Length; i < li; i++) { solutionObjectives = objectives[i]; Solution solution = new Solution(solutionObjectives.Length); solution.Objective = solutionObjectives; solutionSet.Add(solution); } }