- Timestamp:
- 08/29/19 13:53:26 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MultiObjective/DominationCalculator.cs
r16723 r17225 25 25 26 26 namespace HeuristicLab.Optimization { 27 27 28 [StorableType("d76eb753-5088-4490-ad18-e78d3629c60b")] 28 29 public enum DominationResult { Dominates, IsDominated, IsNonDominated }; 29 30 30 public static class DominationCalculator <T>{31 public static class DominationCalculator { 31 32 /// <summary> 32 33 /// Calculates the best pareto front only. The fast non-dominated sorting algorithm is used … … 45 46 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 46 47 /// <returns>The pareto front containing the best solutions and their associated quality resp. fitness.</returns> 47 public static List<Tuple<T, double[]>> CalculateBestParetoFront(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { 48 int populationSize = solutions.Length; 49 48 public static List<Tuple<T, double[]>> CalculateBestParetoFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities = true) { 49 var populationSize = solutions.Length; 50 50 Dictionary<T, List<int>> dominatedIndividuals; 51 51 int[] dominationCounter, rank; … … 71 71 /// <param name="dominateOnEqualQualities">Whether solutions of exactly equal quality should dominate one another.</param> 72 72 /// <returns>A sorted list of the pareto fronts from best to worst.</returns> 73 public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts (T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) {74 intpopulationSize = solutions.Length;73 public static List<List<Tuple<T, double[]>>> CalculateAllParetoFronts<T>(T[] solutions, double[][] qualities, bool[] maximization, out int[] rank, bool dominateOnEqualQualities = true) { 74 var populationSize = solutions.Length; 75 75 76 76 Dictionary<T, List<int>> dominatedIndividuals; … … 78 78 var fronts = new List<List<Tuple<T, double[]>>>(); 79 79 fronts.Add(CalculateBestFront(solutions, qualities, maximization, dominateOnEqualQualities, populationSize, out dominatedIndividuals, out dominationCounter, out rank)); 80 inti = 0;80 var i = 0; 81 81 while (i < fronts.Count && fronts[i].Count > 0) { 82 82 var nextFront = new List<Tuple<T, double[]>>(); … … 84 84 List<int> dominatedIndividualsByp; 85 85 if (dominatedIndividuals.TryGetValue(p.Item1, out dominatedIndividualsByp)) { 86 for ( intk = 0; k < dominatedIndividualsByp.Count; k++) {87 intdominatedIndividual = dominatedIndividualsByp[k];86 for (var k = 0; k < dominatedIndividualsByp.Count; k++) { 87 var dominatedIndividual = dominatedIndividualsByp[k]; 88 88 dominationCounter[dominatedIndividual] -= 1; 89 89 if (dominationCounter[dominatedIndividual] == 0) { … … 100 100 } 101 101 102 private static List<Tuple<T, double[]>> CalculateBestFront (T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) {102 private static List<Tuple<T, double[]>> CalculateBestFront<T>(T[] solutions, double[][] qualities, bool[] maximization, bool dominateOnEqualQualities, int populationSize, out Dictionary<T, List<int>> dominatedIndividuals, out int[] dominationCounter, out int[] rank) { 103 103 var front = new List<Tuple<T, double[]>>(); 104 104 dominatedIndividuals = new Dictionary<T, List<int>>(); 105 105 dominationCounter = new int[populationSize]; 106 106 rank = new int[populationSize]; 107 for ( intpI = 0; pI < populationSize - 1; pI++) {107 for (var pI = 0; pI < populationSize - 1; pI++) { 108 108 var p = solutions[pI]; 109 109 List<int> dominatedIndividualsByp; 110 110 if (!dominatedIndividuals.TryGetValue(p, out dominatedIndividualsByp)) 111 111 dominatedIndividuals[p] = dominatedIndividualsByp = new List<int>(); 112 for ( intqI = pI + 1; qI < populationSize; qI++) {112 for (var qI = pI + 1; qI < populationSize; qI++) { 113 113 var test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities); 114 114 if (test == DominationResult.Dominates) { … … 149 149 if (dominateOnEqualQualities) { 150 150 var equal = true; 151 for ( inti = 0; i < left.Length; i++) {151 for (var i = 0; i < left.Length; i++) { 152 152 if (left[i] != right[i]) { 153 153 equal = false; … … 159 159 160 160 bool leftIsBetter = false, rightIsBetter = false; 161 for ( inti = 0; i < left.Length; i++) {161 for (var i = 0; i < left.Length; i++) { 162 162 if (IsDominated(left[i], right[i], maximizations[i])) rightIsBetter = true; 163 163 else if (IsDominated(right[i], left[i], maximizations[i])) leftIsBetter = true;
Note: See TracChangeset
for help on using the changeset viewer.