Changeset 16171 for branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Utilities.cs
- Timestamp:
- 09/21/18 09:18:49 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Utilities.cs
r15583 r16171 26 26 namespace HeuristicLab.Problems.TestFunctions.MultiObjective { 27 27 internal static class Utilities { 28 internal static double MinimumDistance(double[] point, IEnumerable<double[]> points) {29 if (point == null) throw new ArgumentNullException("Point must not be null.");30 if (points == null) throw new ArgumentNullException("Points must not be null.");31 if (!points.Any()) throw new ArgumentException("Points must not be empty.");32 33 double minDistance = double.MaxValue;34 foreach (double[] r in points) {35 if (r.Length != point.Length) throw new ArgumentException("Dimensions of Points and Point do not match.");36 37 double squaredDistance = 0;38 for (int i = 0; i < r.Length; i++) {39 squaredDistance += (point[i] - r[i]) * (point[i] - r[i]);40 }41 minDistance = Math.Min(squaredDistance, minDistance);42 }43 44 return Math.Sqrt(minDistance);45 }46 47 28 internal static DoubleMatrix ToMatrix(IEnumerable<double[]> source) { 48 29 try { 49 intfirstDimension = source.Count();50 intsecondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular30 var firstDimension = source.Count(); 31 var secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular 51 32 52 33 var result = new DoubleMatrix(firstDimension, secondDimension); 53 34 var enumarator = source.GetEnumerator(); 54 for ( inti = 0; i < firstDimension && enumarator.MoveNext(); ++i)55 for ( intj = 0; j < secondDimension; ++j)35 for (var i = 0; i < firstDimension && enumarator.MoveNext(); ++i) 36 for (var j = 0; j < secondDimension; ++j) 56 37 result[i, j] = enumarator.Current[j]; 57 38 return result; … … 62 43 } 63 44 64 internal class DimensionComparer : IComparer<double[]> { 65 private readonly int dim; 66 private readonly int descending; 67 68 public DimensionComparer(int dimension, bool descending) { 69 this.dim = dimension; 70 this.descending = descending ? -1 : 1; 71 } 72 73 public int Compare(double[] x, double[] y) { 74 if (x[dim] < y[dim]) return -descending; 75 else if (x[dim] > y[dim]) return descending; 76 else return 0; 77 } 78 } 45 79 46 } 80 47 }
Note: See TracChangeset
for help on using the changeset viewer.