Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Analysis/3.3/MultiObjective/HypervolumeAnalyzer.cs @ 16752

Last change on this file since 16752 was 16310, checked in by bwerth, 6 years ago

#2943 worked on MOBasicProblem and MOAnalyzers

File size: 3.7 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.Analysis {
33  [StorableClass]
34  [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
35  public class HypervolumeAnalyzer : MultiObjectiveSuccessAnalyzer {
36    public override string ResultName => "Hypervolume";
37
38    public ILookupParameter<DoubleArray> ReferencePointParameter => (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"];
39
40    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter => (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"];
41
42    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter => (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"];
43
44
45    [StorableConstructor]
46    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) {}
47
48    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) {}
49
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new HypervolumeAnalyzer(this, cloner);
52    }
53
54    public HypervolumeAnalyzer() {
55      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
56      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation", "Results", new DoubleValue(double.NaN)));
57      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
58      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
59      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(double.NaN);
60      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(double.NaN);
61    }
62
63    public override IOperation Apply() {
64      var qualities = QualitiesParameter.ActualValue.Select(x => x.CloneAsArray()).ToArray();
65      var referencePoint = ReferencePointParameter.ActualValue.ToArray();
66      var best = BestKnownHypervolumeResultParameter.ActualValue.Value;
67      var maximization = MaximizationParameter.ActualValue.ToArray();
68
69      var hv = HypervolumeCalculator.CalculateHypervolume(qualities, referencePoint, maximization);
70      if (hv > best || double.IsNaN(best)) best = hv;
71      ResultParameter.ActualValue.Value = hv;
72      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
73      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
74
75      return base.Apply();
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.