Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.cs @ 13776

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

#1087 added ConstrainedFunctions

File size: 3.7 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;
23using System.Linq;
24
25namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
26
27  public class Hypervolume {
28
29    /// <summary>
30    /// The Hyprevolume-metric is defined as the Hypervolume enclosed between a given reference point,
31    /// that is fixed for every evaluation function and the evaluated front.
32    ///
33    /// Example:
34    /// r is the reference Point at (1|1)  and every Point p is part of the evaluated front
35    /// The filled Area labled HV is the 2 diensional Hypervolume enclosed by this front.
36    ///
37    /// (0|1)                (1|1)
38    ///   +      +-------------r
39    ///   |      |###### HV ###|
40    ///   |      p------+######|
41    ///   |             p+#####|
42    ///   |              |#####|
43    ///   |              p-+###|
44    ///   |                p---+
45    ///   |                 
46    ///   +--------------------1
47    /// (0|0)                (1|0)
48    ///
49    ///  Please note that in this example both dimensions are minimized. The reference Point need to be dominated by EVERY point in the evaluated front
50    ///
51    /// </summary>
52    public static double Calculate(IEnumerable<double[]> front, IEnumerable<double> reference, bool[] maximization) {
53      List<double> list = new List<double>();
54      foreach (double d in reference) list.Add(d);
55      double[] refp = list.ToArray<double>();
56      if (front == null) throw new ArgumentException("Fronts must not be null");
57      double[][] set = front.ToArray();   //Still no Good
58      if (set.Length == 0) throw new ArgumentException("Fronts must not be empty");
59      if (refp.Length != set.Length) throw new ArgumentException("Front and referencepoint need to be of the same dimensionality");
60      Array.Sort<double[]>(set, Utilities.getDimensionComparer(0, maximization[0]));
61      double[] last = set[set.Length - 1];
62      CheckConsistency(last, 0, refp, maximization);
63      CheckConsistency(last, 1, refp, maximization);
64
65      double sum = 0;
66      for (int i = 0; i < set.Length - 1; i++) {
67        CheckConsistency(set[i], 1, refp, maximization);
68        sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - refp[1]));
69      }
70
71      sum += Math.Abs(refp[0] - last[0]) * Math.Abs(refp[1] - last[1]);
72      return sum;
73    }
74
75    private static void CheckConsistency(double[] point, int dim, double[] reference, bool[] maximization) {
76      if (!maximization[dim] && point[dim] > reference[dim]) throw new ArgumentException("Reference Point must be dominated by all points of the front");
77      if (maximization[dim] && point[dim] < reference[dim]) throw new ArgumentException("Reference Point must be dominated by all points of the front");
78      if (point.Length != 2) throw new ArgumentException("Only 2-dimensional cases are supported yet");
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.