Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14085 was 14085, checked in by mkommend, 8 years ago

#1087: Further refactoring of testfunction problem and analyzers.

File size: 4.2 KB
RevLine 
[13672]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.Collections.Generic;
[14030]23using System.Linq;
[13672]24using HeuristicLab.Common;
[13725]25using HeuristicLab.Core;
[13672]26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
[13725]28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[13672]30
[13988]31namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
32  [StorableClass]
[14044]33  [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
[13988]34  public class HypervolumeAnalyzer : MOTFAnalyzer {
[14044]35
[14085]36    public ILookupParameter<DoubleArray> ReferencePointParameter {
37      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
[13988]38    }
[14044]39
40    public IFixedValueParameter<DoubleValue> BestKnownHyperVolumeParameter {
41      get { return (IFixedValueParameter<DoubleValue>)Parameters["BestKnownHyperVolume"]; }
42    }
43
44    public double BestKnownHyperVolume {
45      get { return BestKnownHyperVolumeParameter.Value.Value; }
46      set { BestKnownHyperVolumeParameter.Value.Value = value; }
47    }
48
[13988]49    [StorableConstructor]
50    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { }
[13672]51
[14044]52    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
53      : base(original, cloner) {
[13988]54    }
[14044]55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new HypervolumeAnalyzer(this, cloner);
[13988]57    }
[13725]58
[13988]59    public HypervolumeAnalyzer() {
[14085]60      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
[14044]61      Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume", new DoubleValue(0)));
[13988]62    }
[13725]63
[14044]64    public override IOperation Apply() {
65      var results = ResultsParameter.ActualValue;
66      var qualities = QualitiesParameter.ActualValue;
67      var testFunction = TestFunctionParameter.ActualValue;
[14085]68      var referencePoint = ReferencePointParameter.ActualValue;
[13988]69      int objectives = qualities[0].Length;
[13672]70
[14085]71
72
[13988]73      if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue)));
[14030]74      if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", typeof(DoubleValue)));
[14044]75
[14030]76      double best;
77      if (!results.ContainsKey("BestKnownHypervolume")) {
78        results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue)));
79        best = BestKnownHyperVolumeParameter.Value.Value;
80      } else {
81        best = ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value;
[13988]82      }
[13672]83
[14044]84
[14081]85      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
[14044]86
[14085]87      double hv = front.Any() ? Hypervolume.Calculate(front, referencePoint.CloneAsArray(), testFunction.Maximization(objectives)) : 0;
[14044]88
89
90      if (double.IsNaN(best) || best < hv) {
91        best = hv;
92        BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray()));
[13988]93      }
[13672]94
[13988]95      results["Hypervolume"].Value = new DoubleValue(hv);
96      results["BestKnownHypervolume"].Value = new DoubleValue(best);
[14044]97      results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(best - hv);
[13936]98
[14044]99      return base.Apply();
[13672]100    }
[14044]101
[13988]102  }
[13672]103}
Note: See TracBrowser for help on using the repository browser.