Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/09/16 12:44:23 (8 years ago)
Author:
bwerth
Message:

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

Location:
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.cs

    r13620 r13672  
    1 using System;
     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;
    222using System.Collections.Generic;
    323using System.Linq;
    4 using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators;
    524
    625namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    7   /// <summary>
    8   /// The Hyprevolume-metric is defined as the Hypervolume enclosed between a given reference point,
    9   /// that is fixed for every evaluation function and the evaluated front.
    10   ///
    11   /// Example:
    12   /// r is the reference Point at (1|1)  and every Point p is part of the evaluated front
    13   /// The filled Area labled HV is the 2 diensional Hypervolume enclosed by this front.
    14   ///
    15   /// (0|1)                (1|1)
    16   ///   +      +-------------r
    17   ///   |      |###### HV ###|
    18   ///   |      p------+######|
    19   ///   |             p+#####|
    20   ///   |              |#####|
    21   ///   |              p-+###|
    22   ///   |                p---+
    23   ///   |                 
    24   ///   +--------------------1
    25   /// (0|0)                (1|0)
    26   ///
    27   ///  Please note that in this example both dimensions are minimized. The reference Point need to be dominated by EVERY point in the evaluated front
    28   ///
    29   /// </summary>
    30   public class Hypervolume : IMultiObjectiveDistance {
    3126
    32     private double[] reference;
    33     private bool[] maximization;
    34     public Hypervolume(double[] reference, bool[] maximization) {
    35       if (reference.Length != 2) throw new Exception("Only 2-dimensional cases are supported yet");
    36       this.reference = reference;
    37       this.maximization = maximization;
    38     }
     27  public class Hypervolume {
    3928
    40     public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
    41       return GetHypervolume(optimalFront) - GetHypervolume(front);
    42 
    43     }
    44 
    45     public double GetHypervolume(IEnumerable<double[]> front) {
     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) {
    4653      if (front == null) throw new ArgumentException("Fronts must not be null");
    4754      //TODO what to do if set contains dominated points
     
    5057      Array.Sort<double[]>(set, Utilities.getDimensionComparer(0, maximization[0]));
    5158      double[] last = set[set.Length - 1];
    52       CheckConsistency(last, 0);
    53       CheckConsistency(last, 1);
     59      CheckConsistency(last, 0, reference, maximization);
     60      CheckConsistency(last, 1, reference, maximization);
     61
    5462      double sum = 0;
    5563      for (int i = 0; i < set.Length - 1; i++) {
    56         CheckConsistency(set[i], 1);
     64        CheckConsistency(set[i], 1, reference, maximization);
    5765        sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - reference[1]));
    5866      }
     
    6270    }
    6371
    64     public static double GetHypervolume(IEnumerable<double[]> front, double[] reference, bool[] maximization){
    65       Hypervolume comp = new Hypervolume(reference, maximization);
    66       return comp.GetHypervolume(front);
    67     }
    68 
    69     public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront, double[] reference, bool[] maximization) {
    70       return GetHypervolume(optimalFront, reference, maximization) - GetHypervolume(front, reference, maximization);
    71     }
    72 
    73     private void CheckConsistency(double[] point, int dim) {
     72    private static void CheckConsistency(double[] point, int dim, double[] reference, bool[] maximization) {
    7473      if (!maximization[dim] && point[dim] > reference[dim]) throw new ArgumentException("Reference Point must be dominated by all points of the front");
    7574      if (maximization[dim] && point[dim] < reference[dim]) throw new ArgumentException("Reference Point must be dominated by all points of the front");
Note: See TracChangeset for help on using the changeset viewer.