Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1087 added Analyzers, reworked PFStore, added licence information, cleaned code

File size: 2.5 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        for (int i = 0; i < r.Length; i++) {
42          d += (point[i] - r[i]) * (point[i] - r[i]);
43        }
44        min = Math.Min(d, min);
45      }
46      if (empty) throw new ArgumentException("Fronts must not be empty");
47      if (min == double.MaxValue) { return -1; }
48      return Math.Sqrt(min);
49    }
50
51    internal static IComparer<double[]> getDimensionComparer(int dim, bool descending) {
52      return new DimensionComparer(dim, descending);
53    }
54
55
56    internal class DimensionComparer : IComparer<double[]> {
57      private int dim;
58      private int descending;
59
60      public DimensionComparer(int dimension, bool descending) {
61        this.dim = dimension;
62        this.descending = descending ? -1 : 1;
63      }
64
65      #region IComparer<DoubleArray> Members
66
67      public int Compare(double[] x, double[] y) {
68        if (x[dim] < y[dim]) return -descending;
69        else if (x[dim] > y[dim]) return descending;
70        else return 0;
71      }
72
73      #endregion
74    }
75  }
76
77
78
79
80
81}
Note: See TracBrowser for help on using the repository browser.