Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs @ 15831

Last change on this file since 15831 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
33  [StorableClass]
34  [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
35  public class HypervolumeAnalyzer : MOTFAnalyzer {
36
37    public ILookupParameter<DoubleArray> ReferencePointParameter {
38      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
39    }
40    public IResultParameter<DoubleValue> HypervolumeResultParameter {
41      get { return (IResultParameter<DoubleValue>)Parameters["Hypervolume"]; }
42    }
43    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter {
44      get { return (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"]; }
45    }
46    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter {
47      get { return (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"]; }
48    }
49
50
51    [StorableConstructor]
52    protected HypervolumeAnalyzer(bool deserializing)
53      : base(deserializing) {
54    }
55
56    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
57      : base(original, cloner) {
58    }
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new HypervolumeAnalyzer(this, cloner);
61    }
62
63    public HypervolumeAnalyzer() {
64      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
65      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
66      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
67      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
68      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
69      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
70      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
71
72
73    }
74
75    public override IOperation Apply() {
76      var qualities = QualitiesParameter.ActualValue;
77      var testFunction = TestFunctionParameter.ActualValue;
78      int objectives = qualities[0].Length;
79      var referencePoint = ReferencePointParameter.ActualValue;
80
81      double best = BestKnownHypervolumeResultParameter.ActualValue.Value;
82      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
83        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
84      }
85
86      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
87
88      double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives));
89
90      if (hv > best) {
91        best = hv;
92      }
93
94      HypervolumeResultParameter.ActualValue.Value = hv;
95      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
96      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
97
98      return base.Apply();
99    }
100
101  }
102}
Note: See TracBrowser for help on using the repository browser.