- Timestamp:
- 07/22/20 12:53:10 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3Selection.cs
r17668 r17692 15 15 /// have the same number of objectives, undefined behavior happens. 16 16 /// </summary> 17 /// <param name="rt"> </param>17 /// <param name="rt">The previous generation and its mutated children.</param> 18 18 /// <param name="referencePoints"></param> 19 19 /// <param name="maximization"></param> 20 /// <param name="N">Number of solutions to select.</param> 21 /// <param name="random">The <see cref="IRandom" /> to use for randomness.</param> 20 22 /// <returns></returns> 21 public static List<Solution> SelectSolutionsForNextGeneration(List<Solution> rt, List<ReferencePoint> referencePoints, bool[] maximization, IRandom random) 22 { 23 int N = rt.Count / 2; // number of solutions in a generation 23 public static List<Solution> SelectSolutionsForNextGeneration(List<Solution> rt, List<ReferencePoint> referencePoints, bool[] maximization, int N, IRandom random) 24 { 24 25 int numberOfObjectives = rt.First().Fitness.Length; 25 26 List<Solution> st = new List<Solution>(); … … 64 65 // Find the ideal point 65 66 double[] idealPoint = new double[numberOfObjectives]; 67 68 foreach (var solution in st) 69 solution.ConvertedFitness = new double[numberOfObjectives]; 70 66 71 for (int j = 0; j < numberOfObjectives; j++) 67 72 { … … 69 74 idealPoint[j] = Utility.Min(s => s.Fitness[j], st); 70 75 71 // Translate objectives 76 // Translate objectives and save the modified fitness values in ConvertedFitness 72 77 foreach (var solution in st) 73 solution. Fitness[j] -=idealPoint[j];78 solution.ConvertedFitness[j] = solution.Fitness[j] - idealPoint[j]; 74 79 } 75 80 … … 83 88 weights[j] = 1; 84 89 85 extremePoints[j] = Utility.ArgMin(s => ASF(s. Fitness, weights), st);90 extremePoints[j] = Utility.ArgMin(s => ASF(s.ConvertedFitness, weights), st); 86 91 } 87 92 … … 103 108 if (Math.Abs(intercepts[i] - idealPoint[i]) > EPSILON) 104 109 { 105 solution. Fitness[i] = solution.Fitness[i] / (intercepts[i] - idealPoint[i]);110 solution.ConvertedFitness[i] = solution.ConvertedFitness[i] / (intercepts[i] - idealPoint[i]); 106 111 } 107 112 else 108 113 { 109 solution. Fitness[i] = solution.Fitness[i] / EPSILON;114 solution.ConvertedFitness[i] = solution.ConvertedFitness[i] / EPSILON; 110 115 } 111 116 } … … 121 126 // find reference point for which the perpendicular distance to the current 122 127 // solution is the lowest 123 var rpAndDist = Utility.MinArgMin(rp => GetPerpendicularDistance(rp.Values, solution. Fitness), referencePoints);128 var rpAndDist = Utility.MinArgMin(rp => GetPerpendicularDistance(rp.Values, solution.ConvertedFitness), referencePoints); 124 129 // associated reference point 125 130 var arp = rpAndDist.Item1; … … 235 240 for (int j = i + 1; !duplicate && j < extremePoints.Count; j++) 236 241 { 237 // maybe todo: override Equals method of solution? 238 duplicate = extremePoints[i].Equals(extremePoints[j]); 242 duplicate = extremePoints[i] == extremePoints[j]; 239 243 } 240 244 } … … 242 246 List<double> intercepts = new List<double>(); 243 247 248 // todo: do handling of this case as in Tsung Che Chiang's implementation 244 249 if (duplicate) 245 250 { // cannot construct the unique hyperplane (this is a casual method to deal with the condition) … … 248 253 // extreme_points[f] stands for the individual with the largest value of 249 254 // objective f 250 intercepts.Add(extremePoints[f]. Fitness[f]);255 intercepts.Add(extremePoints[f].ConvertedFitness[f]); 251 256 } 252 257 } … … 260 265 } 261 266 262 List<List<double>> a = new List<List<double>>(); 263 foreach (Solution s in extremePoints) 264 { 265 List<double> aux = new List<double>(); 266 for (int i = 0; i < numberOfObjectives; i++) 267 aux.Add(s.Fitness[i]); 268 a.Add(aux); 269 } 267 List<List<double>> a = extremePoints.Select(p => p.ConvertedFitness.ToList()).ToList(); 268 270 269 List<double> x = GaussianElimination(a, b); 271 270
Note: See TracChangeset
for help on using the changeset viewer.