Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/18 09:18:49 (6 years ago)
Author:
bwerth
Message:

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Utilities.cs

    r15583 r16171  
    2626namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
    2727  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 
    4728    internal static DoubleMatrix ToMatrix(IEnumerable<double[]> source) {
    4829      try {
    49         int firstDimension = source.Count();
    50         int secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
     30        var firstDimension = source.Count();
     31        var secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
    5132
    5233        var result = new DoubleMatrix(firstDimension, secondDimension);
    5334        var enumarator = source.GetEnumerator();
    54         for (int i = 0; i < firstDimension && enumarator.MoveNext(); ++i)
    55           for (int j = 0; j < secondDimension; ++j)
     35        for (var i = 0; i < firstDimension && enumarator.MoveNext(); ++i)
     36          for (var j = 0; j < secondDimension; ++j)
    5637            result[i, j] = enumarator.Current[j];
    5738        return result;
     
    6243    }
    6344
    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   
    7946  }
    8047}
Note: See TracChangeset for help on using the changeset viewer.