Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs @ 16886

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

#2943 worked on MOBasicProblem and MOAnalyzers

File size: 4.1 KB
RevLine 
[13672]1#region License Information
2/* HeuristicLab
[15583]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13672]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
[14090]22using System;
[13672]23using System.Collections.Generic;
[14030]24using System.Linq;
[13672]25using HeuristicLab.Common;
[13725]26using HeuristicLab.Core;
[13672]27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
[13725]29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[13672]31
[14111]32namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
[13988]33  [StorableClass]
[16310]34  [Item("HypervolumeAnalyzer", "This analyzer is functionally equivalent to the HypervolumeAnalyzer in HeuristicLab.Analysis, but is kept as not to break backwards compatibility")]
[13988]35  public class HypervolumeAnalyzer : MOTFAnalyzer {
[14044]36
[16310]37    public ILookupParameter<DoubleArray> ReferencePointParameter => (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"];
[14092]38
[16310]39    public IResultParameter<DoubleValue> HypervolumeResultParameter => (IResultParameter<DoubleValue>)Parameters["Hypervolume"];
[14097]40
[16310]41    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter => (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"];
42
43    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter => (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"];
44
45
[13988]46    [StorableConstructor]
[16310]47    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) {}
[13672]48
[16310]49    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) {}
50
[14044]51    public override IDeepCloneable Clone(Cloner cloner) {
52      return new HypervolumeAnalyzer(this, cloner);
[13988]53    }
[13725]54
[14092]55    public HypervolumeAnalyzer() {
56      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
[14097]57      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
58      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
59      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
60      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
61      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
62      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
[14092]63    }
[13725]64
[14044]65    public override IOperation Apply() {
66      var qualities = QualitiesParameter.ActualValue;
67      var testFunction = TestFunctionParameter.ActualValue;
[16171]68      var objectives = qualities[0].Length;
[14092]69      var referencePoint = ReferencePointParameter.ActualValue;
[13672]70
[16171]71      var best = BestKnownHypervolumeResultParameter.ActualValue.Value;
[14097]72      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
73        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
[13988]74      }
[13672]75
[16171]76      var hv = HypervolumeCalculator.CalculateHypervolume(qualities.Select(x=>x.CloneAsArray()).ToArray(), referencePoint.ToArray(), testFunction.Maximization(objectives));
[14044]77
[14108]78      if (hv > best) {
[14044]79        best = hv;
[13988]80      }
[13672]81
[14097]82      HypervolumeResultParameter.ActualValue.Value = hv;
83      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
84      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
[13936]85
[14044]86      return base.Apply();
[13672]87    }
[14044]88
[13988]89  }
[13672]90}
Note: See TracBrowser for help on using the repository browser.