Changeset 14030 for branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.cs
- Timestamp:
- 07/08/16 15:30:46 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.cs
r14018 r14030 52 52 /// </summary> 53 53 /// 54 public static double Calculate(IEnumerable<double[]> points, double[] referencePoint, bool[] maximization) {55 var front = NonDominatedSelect.removeNonReferenceDominatingVectors(points, referencePoint, maximization, false);54 public static double Calculate(IEnumerable<double[]> front, double[] referencePoint, bool[] maximization) { 55 front = NonDominatedSelect.removeNonReferenceDominatingVectors(front, referencePoint, maximization, false); 56 56 if (maximization.Length == 2) 57 57 return Calculate2D(front, referencePoint, maximization); 58 58 59 59 if (Array.TrueForAll(maximization, x => !x)) 60 return CalculateM D(front, referencePoint);60 return CalculateMulitDimensional(front, referencePoint); 61 61 else throw new NotImplementedException("Hypervolume calculation for more than two dimensions is supported only with minimization problems."); 62 62 } … … 70 70 if (referencePoint.Length != 2) throw new ArgumentException("ReferencePoint must have exactly two dimensions."); 71 71 72 double[][] set = front.ToArray(); //Still no Good72 double[][] set = front.ToArray(); 73 73 if (set.Any(s => s.Length != 2)) throw new ArgumentException("Points in front must have exactly two dimensions."); 74 74 … … 77 77 double sum = 0; 78 78 for (int i = 0; i < set.Length - 1; i++) { 79 if (NonDominatedSelect.Dominates(referencePoint, set[i], maximization, true) == NonDominatedSelect.DominationResult.Dominates)80 throw new ArgumentException("Reference Point must be dominated by all points of the front");81 79 sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - referencePoint[1])); 82 80 } 83 81 84 82 double[] lastPoint = set[set.Length - 1]; 85 if (NonDominatedSelect.Dominates(referencePoint, lastPoint, maximization, true) == NonDominatedSelect.DominationResult.Dominates)86 throw new ArgumentException("Reference Point must be dominated by all points of the front");87 83 sum += Math.Abs(lastPoint[0] - referencePoint[0]) * Math.Abs(lastPoint[1] - referencePoint[1]); 88 84 … … 92 88 93 89 94 private static double CalculateM D(IEnumerable<double[]> points, double[] referencePoint) {90 private static double CalculateMulitDimensional(IEnumerable<double[]> front, double[] referencePoint) { 95 91 if (referencePoint == null || referencePoint.Length < 3) throw new ArgumentException("ReferencePoint unfit for complex Hypervolume calculation"); 96 if (!IsDominated(referencePoint, points)) {97 throw new ArgumentException("ReferencePoint unfit for complex Hypervolume calculation");98 }99 92 100 93 int objectives = referencePoint.Length; 101 var fron t = points.ToList();102 fron t.StableSort(new Utilities.DimensionComparer(objectives - 1, false));94 var fronList = front.ToList(); 95 fronList.StableSort(new Utilities.DimensionComparer(objectives - 1, false)); 103 96 104 97 double[] regLow = Enumerable.Repeat(1E15, objectives).ToArray(); 105 foreach (double[] p in fron t) {98 foreach (double[] p in fronList) { 106 99 for (int i = 0; i < regLow.Length; i++) { 107 100 if (p[i] < regLow[i]) regLow[i] = p[i]; … … 109 102 } 110 103 111 return Stream(regLow, referencePoint, front, 0, referencePoint[objectives - 1], (int)Math.Sqrt(front.Count), objectives); 112 } 113 114 private static bool IsDominated(double[] referencePoint, IEnumerable<double[]> points) { 115 foreach (double[] point in points) { 116 for (int i = 0; i < referencePoint.Length; i++) { 117 if (referencePoint[i] < point[i]) { 118 return false; 119 } 120 } 121 } 122 return true; 123 } 124 125 private static double Stream(double[] regionLow, double[] regionUp, List<double[]> points, int split, double cover, int sqrtNoPoints, int objectives) { 104 return Stream(regLow, referencePoint, fronList, 0, referencePoint[objectives - 1], (int)Math.Sqrt(fronList.Count), objectives); 105 } 106 107 private static double Stream(double[] regionLow, double[] regionUp, List<double[]> front, int split, double cover, int sqrtNoPoints, int objectives) { 126 108 double coverOld = cover; 127 109 int coverIndex = 0; … … 131 113 132 114 double dMeasure = GetMeasure(regionLow, regionUp, objectives); 133 while (cover == coverOld && coverIndex < points.Count()) {115 while (cover == coverOld && coverIndex < front.Count()) { 134 116 if (coverIndexOld == coverIndex) break; 135 117 coverIndexOld = coverIndex; 136 if (Covers( points[coverIndex], regionLow, objectives)) {137 cover = points[coverIndex][objectives - 1];118 if (Covers(front[coverIndex], regionLow, objectives)) { 119 cover = front[coverIndex][objectives - 1]; 138 120 result += dMeasure * (coverOld - cover); 139 121 } else coverIndex++; … … 141 123 } 142 124 143 for (c = coverIndex; c > 0; c--) if ( points[c - 1][objectives - 1] == cover) coverIndex--;125 for (c = coverIndex; c > 0; c--) if (front[c - 1][objectives - 1] == cover) coverIndex--; 144 126 if (coverIndex == 0) return result; 145 127 … … 147 129 int[] piles = new int[coverIndex]; 148 130 for (int i = 0; i < coverIndex; i++) { 149 piles[i] = IsPile( points[i], regionLow, regionUp, objectives);131 piles[i] = IsPile(front[i], regionLow, regionUp, objectives); 150 132 if (piles[i] == -1) { 151 133 allPiles = false; … … 161 143 int i = 0; 162 144 do { 163 current = points[i][objectives - 1];145 current = front[i][objectives - 1]; 164 146 do { 165 if ( points[i][piles[i]] < trellis[piles[i]]) trellis[piles[i]] = points[i][piles[i]];147 if (front[i][piles[i]] < trellis[piles[i]]) trellis[piles[i]] = front[i][piles[i]]; 166 148 i++; 167 if (i < coverIndex) next = points[i][objectives - 1];149 if (i < coverIndex) next = front[i][objectives - 1]; 168 150 else { next = cover; break; } 169 151 } while (next == current); … … 179 161 do { 180 162 for (int i = 0; i < coverIndex; i++) { 181 int contained = ContainesBoundary( points[i], regionLow, split);182 if (contained == 0) boundaries[boundIdx++] = points[i][split];183 else if (contained == 1) noBoundaries[noBoundIdx++] = points[i][split];163 int contained = ContainesBoundary(front[i], regionLow, split); 164 if (contained == 0) boundaries[boundIdx++] = front[i][split]; 165 else if (contained == 1) noBoundaries[noBoundIdx++] = front[i][split]; 184 166 } 185 167 if (boundIdx > 0) bound = GetMedian(boundaries, boundIdx); … … 197 179 198 180 for (int i = 0; i < coverIndex; i++) { 199 if (PartCovers( points[i], regionUpC, objectives)) pointsChildUp.Add(points[i]);200 if (PartCovers( points[i], regionUp, objectives)) pointsChildLow.Add(points[i]);181 if (PartCovers(front[i], regionUpC, objectives)) pointsChildUp.Add(front[i]); 182 if (PartCovers(front[i], regionUp, objectives)) pointsChildLow.Add(front[i]); 201 183 } 202 184 //this could/should be done in Parallel
Note: See TracChangeset
for help on using the changeset viewer.