Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.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: 3.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;
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, double[] reference, bool[] maximization) {
53      if (front == null) throw new ArgumentException("Fronts must not be null");
54      //TODO what to do if set contains dominated points
55      double[][] set = front.ToArray();   //Still no Good
56      if (set.Length == 0) throw new ArgumentException("Fronts must not be empty");
57      Array.Sort<double[]>(set, Utilities.getDimensionComparer(0, maximization[0]));
58      double[] last = set[set.Length - 1];
59      CheckConsistency(last, 0, reference, maximization);
60      CheckConsistency(last, 1, reference, maximization);
61
62      double sum = 0;
63      for (int i = 0; i < set.Length - 1; i++) {
64        CheckConsistency(set[i], 1, reference, maximization);
65        sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - reference[1]));
66      }
67
68      sum += Math.Abs(reference[0] - last[0]) * Math.Abs(reference[1] - last[1]);
69      return sum;
70    }
71
72    private static void CheckConsistency(double[] point, int dim, double[] reference, bool[] maximization) {
73      if (!maximization[dim] && point[dim] > reference[dim]) throw new ArgumentException("Reference Point must be dominated by all points of the front");
74      if (maximization[dim] && point[dim] < reference[dim]) throw new ArgumentException("Reference Point must be dominated by all points of the front");
75      if (point.Length != 2) throw new ArgumentException("Only 2-dimensional cases are supported yet");
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.