Changeset 13620 for branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/GenerationalDistance.cs
- Timestamp:
- 02/15/16 17:19:34 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/GenerationalDistance.cs
r13562 r13620 1 1 using System; 2 using System.Collections.Generic; 2 3 using HeuristicLab.Encodings.RealVectorEncoding; 4 using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators; 3 5 4 6 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { … … 15 17 } 16 18 17 18 public static double GetDistance(RealVector[] front, RealVector[] optimalFront, double p) { 19 public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront, double p) { 19 20 return new GenerationalDistance(p).Compare(front,optimalFront); 20 21 } 21 22 22 public double Compare(RealVector[] front, RealVector[] optimalFront) { 23 //TODO build a kd-tree, sort the array, do someting intelligent here 24 double sum = 0; 25 if (front.Length == 0 || optimalFront.Length == 0) throw new Exception("Both Fronts need to contain at least one point"); 26 foreach(RealVector r in front) { 27 sum += minDistance(r, optimalFront); 23 public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) { 24 //TODO build a kd-tree, sort the array, do someting intelligent here 25 if (front == null || optimalFront == null) throw new ArgumentException("Fronts must not be null"); 26 double sum = 0; 27 int c = 0; 28 foreach(double[] r in front) { 29 sum += Utilities.minDistance(r, optimalFront,true); 30 c++; 28 31 } 29 return Math.Pow(sum, p) /front.Length; 32 if (c == 0) throw new ArgumentException("Fronts must not be empty"); 33 return Math.Pow(sum, p) /c; 30 34 } 31 35 32 private double minDistance(RealVector point, RealVector[] list) { 33 //TODO inefficient 34 double min = Double.MaxValue; 35 foreach (RealVector r in list) { 36 if (r == point) continue; 37 double d = 0; 38 for (int i = 0; i < r.Length; i++) { 39 d += (point[i] - r[i]) * (point[i] - r[i]); 40 } 41 min = Math.Min(d, min); 42 } 43 return Math.Sqrt(min); 44 } 36 45 37 46 38 }
Note: See TracChangeset
for help on using the changeset viewer.