Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs @ 17226

Last change on this file since 17226 was 17226, checked in by mkommend, 5 years ago

#2521: Merged trunk changes into problem refactoring branch.

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HEAL.Attic;
31
32namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
33  [StorableType("13D363E4-76FF-4A5A-9B2C-767D9E880E4B")]
34  [Item("HypervolumeAnalyzer", "This analyzer is functionally equivalent to the HypervolumeAnalyzer in HeuristicLab.Analysis, but is kept as not to break backwards compatibility")]
35  public class HypervolumeAnalyzer : MOTFAnalyzer {
36
37    public ILookupParameter<DoubleArray> ReferencePointParameter {
38      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
39    }
40
41    public IResultParameter<DoubleValue> HypervolumeResultParameter {
42      get { return (IResultParameter<DoubleValue>)Parameters["Hypervolume"]; }
43    }
44
45    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter {
46      get { return (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"]; }
47    }
48
49    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter {
50      get { return (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"]; }
51    }
52
53
54    [StorableConstructor]
55    protected HypervolumeAnalyzer(StorableConstructorFlag _) : base(_) {
56    }
57
58    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) {}
59
60    public override IDeepCloneable Clone(Cloner cloner) {
61      return new HypervolumeAnalyzer(this, cloner);
62    }
63
64    public HypervolumeAnalyzer() {
65      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
66      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
67      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
68      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
69      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
70      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
71      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
72    }
73
74    public override IOperation Apply() {
75      var qualities = QualitiesParameter.ActualValue;
76      var testFunction = TestFunctionParameter.ActualValue;
77      var objectives = qualities[0].Length;
78      var referencePoint = ReferencePointParameter.ActualValue;
79
80      var best = BestKnownHypervolumeResultParameter.ActualValue.Value;
81      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
82        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
83      }
84
85      var hv = HypervolumeCalculator.CalculateHypervolume(qualities.Select(x=>x.CloneAsArray()).ToArray(), referencePoint.ToArray(), testFunction.Maximization(objectives));
86
87      if (hv > best) {
88        best = hv;
89      }
90
91      HypervolumeResultParameter.ActualValue.Value = hv;
92      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
93      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
94
95      return base.Apply();
96    }
97
98  }
99}
Note: See TracBrowser for help on using the repository browser.