- Timestamp:
- 09/03/19 15:50:35 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective/DominationCalculator.cs
r17226 r17230 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HEAL.Attic; 25 26 … … 137 138 138 139 /// <summary> 140 /// Calculates all pareto fronts by returning the index of the parameters in each front. 141 /// The first in the list is the best front. 142 /// The fast non-dominated sorting algorithm is used as described in 143 /// Deb, K., Pratap, A., Agarwal, S., and Meyarivan, T. (2002). 144 /// A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II. 145 /// IEEE Transactions on Evolutionary Computation, 6(2), 182-197. 146 /// </summary> 147 /// <remarks> 148 /// When there are plateaus in the fitness landscape several solutions might have exactly 149 /// the same fitness vector. In this case parameter <paramref name="dominateOnEqualQualities"/> 150 /// can be set to true to avoid plateaus becoming too attractive for the search process. 151 /// </remarks> 152 /// <param name="solutions">The solutions of the population.</param> 153 /// <param name="qualities">The qualities resp. fitness for each solution.</param> 154 /// <param name="maximization">The objective in each dimension.</param> 155 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 156 /// <returns>A sorted list of the pareto fronts where each front contains the indices of the <paramref name="solutions"/> and <paramref name="qualities"/>.</returns> 157 public static List<List<int>> CalculateAllParetoFrontsIndices<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { 158 return CalculateAllParetoFrontsIndices(solutions, qualities, maximization, out var rank, dominateOnEqualQualities); 159 } 160 161 /// <summary> 162 /// Calculates all pareto fronts by returning the index of the parameters in each front. 163 /// The first in the list is the best front. 164 /// The fast non-dominated sorting algorithm is used as described in 165 /// Deb, K., Pratap, A., Agarwal, S., and Meyarivan, T. (2002). 166 /// A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II. 167 /// IEEE Transactions on Evolutionary Computation, 6(2), 182-197. 168 /// </summary> 169 /// <remarks> 170 /// When there are plateaus in the fitness landscape several solutions might have exactly 171 /// the same fitness vector. In this case parameter <paramref name="dominateOnEqualQualities"/> 172 /// can be set to true to avoid plateaus becoming too attractive for the search process. 173 /// </remarks> 174 /// <param name="solutions">The solutions of the population.</param> 175 /// <param name="qualities">The qualities resp. fitness for each solution.</param> 176 /// <param name="maximization">The objective in each dimension.</param> 177 /// <param name="rank">The rank of each of the solutions, corresponds to the front it is put in.</param> 178 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 179 /// <returns>A sorted list of the pareto fronts where each front contains the indices of the <paramref name="solutions"/> and <paramref name="qualities"/>.</returns> 180 public static List<List<int>> CalculateAllParetoFrontsIndices<T>(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { 181 var populationSize = solutions.Length; 182 183 var dominatedIndividuals = Enumerable.Range(0, qualities.Length).Select(x => new List<int>()).ToArray(); 184 var dominationCounter = new int[populationSize]; 185 rank = new int[populationSize]; 186 var fronts = new List<List<int>>(); 187 fronts.Add(CalculateBestFrontIndices(solutions, qualities, maximization, dominateOnEqualQualities, populationSize, dominatedIndividuals, dominationCounter, rank)); 188 var i = 0; 189 while (i < fronts.Count && fronts[i].Count > 0) { 190 var nextFront = new List<int>(); 191 foreach (var p in fronts[i]) { 192 if (dominatedIndividuals[p].Count > 0) { 193 for (var k = 0; k < dominatedIndividuals[p].Count; k++) { 194 var dominatedIndividual = dominatedIndividuals[p][k]; 195 dominationCounter[dominatedIndividual] -= 1; 196 if (dominationCounter[dominatedIndividual] == 0) { 197 rank[dominatedIndividual] = i + 1; 198 nextFront.Add(dominatedIndividual); 199 } 200 } 201 } 202 } 203 i += 1; 204 fronts.Add(nextFront); 205 } 206 return fronts; 207 } 208 209 private static List<int> CalculateBestFrontIndices<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, List<int>[] dominatedIndividuals, int[] dominationCounter, int[] rank) { 210 var front = new List<int>(); 211 for (var pI = 0; pI < populationSize - 1; pI++) { 212 var p = solutions[pI]; 213 for (var qI = pI + 1; qI < populationSize; qI++) { 214 var test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities); 215 if (test == DominationResult.Dominates) { 216 dominatedIndividuals[pI].Add(qI); 217 dominationCounter[qI] += 1; 218 } else if (test == DominationResult.IsDominated) { 219 dominationCounter[pI] += 1; 220 dominatedIndividuals[qI].Add(pI); 221 } 222 if (pI == populationSize - 2 223 && qI == populationSize - 1 224 && dominationCounter[qI] == 0) { 225 rank[qI] = 0; 226 front.Add(qI); 227 } 228 } 229 if (dominationCounter[pI] == 0) { 230 rank[pI] = 0; 231 front.Add(pI); 232 } 233 } 234 return front; 235 } 236 237 /// <summary> 139 238 /// Calculates the domination result of two solutions which are given in form 140 239 /// of their quality resp. fitness vector.
Note: See TracChangeset
for help on using the changeset viewer.