Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs @ 14090

Last change on this file since 14090 was 14090, checked in by bwerth, 8 years ago

#1087 several fixes according to the review comments 35 and 38

File size: 3.4 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
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.MultiObjectiveTestFunctions {
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    [StorableConstructor]
38    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { }
39
40    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
41      : base(original, cloner) {
42    }
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new HypervolumeAnalyzer(this, cloner);
45    }
46
47    public HypervolumeAnalyzer() { }
48
49    public override IOperation Apply() {
50      var results = ResultsParameter.ActualValue;
51      var qualities = QualitiesParameter.ActualValue;
52      var testFunction = TestFunctionParameter.ActualValue;
53      int objectives = qualities[0].Length;
54      var referencePoint = testFunction.ReferencePoint(objectives);
55
56      if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue)));
57      if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", typeof(DoubleValue)));
58
59      double best = testFunction.OptimalHypervolume(objectives);
60      if (!results.ContainsKey("BestKnownHypervolume")) {
61        results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue)));
62      }
63      best = Math.Max(best, ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value);
64
65      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
66
67      double hv = Hypervolume.Calculate(front, (double[])referencePoint.Clone(), testFunction.Maximization(objectives));
68
69      if (double.IsNaN(best) || best < hv) {
70        best = hv;
71        BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray()));
72      }
73
74      ((DoubleValue)(results["Hypervolume"].Value)).Value = hv;
75      ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value = best;
76      ((DoubleValue)(results["Absolute Distance to BestKnownHypervolume"].Value)).Value = best - hv;
77
78      return base.Apply();
79    }
80
81  }
82}
Note: See TracBrowser for help on using the repository browser.