Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/Utilities.cs @ 13771

Last change on this file since 13771 was 13771, checked in by bwerth, 8 years ago

#1087 bugfix + additional relative HV calculation added

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21using System;
22using System.Collections.Generic;
23
24namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
25  internal class Utilities {
26
27    /// <summary>
28    ///
29    /// </summary>
30    /// <param name="point"></param>
31    /// <param name="list"></param>
32    /// <param name="reflexive"></param>
33    /// <returns>return -1 if list contains only rejected points</returns>
34    internal static double minDistance(double[] point, IEnumerable<double[]> list, bool reflexive) {
35      double min = double.MaxValue;
36      bool empty = true;
37      foreach (double[] r in list) {
38        empty = false;
39        if (!reflexive && ReferenceEquals(r, point)) continue;
40        double d = 0;
41        if (r.Length != point.Length) throw new ArgumentException("dimensions of Front and Point do not match");
42        for (int i = 0; i < r.Length; i++) {
43          d += (point[i] - r[i]) * (point[i] - r[i]);
44        }
45        min = Math.Min(d, min);
46      }
47      if (empty) throw new ArgumentException("Fronts must not be empty");
48      if (min == double.MaxValue) { return -1; }
49      return Math.Sqrt(min);
50    }
51
52    internal static IComparer<double[]> getDimensionComparer(int dim, bool descending) {
53      return new DimensionComparer(dim, descending);
54    }
55
56
57    internal class DimensionComparer : IComparer<double[]> {
58      private int dim;
59      private int descending;
60
61      public DimensionComparer(int dimension, bool descending) {
62        this.dim = dimension;
63        this.descending = descending ? -1 : 1;
64      }
65
66      #region IComparer<DoubleArray> Members
67
68      public int Compare(double[] x, double[] y) {
69        if (x[dim] < y[dim]) return -descending;
70        else if (x[dim] > y[dim]) return descending;
71        else return 0;
72      }
73
74      #endregion
75    }
76  }
77
78
79
80
81
82}
Note: See TracBrowser for help on using the repository browser.