Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs @ 16824

Last change on this file since 16824 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 4.3 KB
RevLine 
[13672]1#region License Information
2/* HeuristicLab
[15584]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]
[14044]34  [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
[13988]35  public class HypervolumeAnalyzer : MOTFAnalyzer {
[14044]36
[14092]37    public ILookupParameter<DoubleArray> ReferencePointParameter {
38      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
39    }
[14097]40    public IResultParameter<DoubleValue> HypervolumeResultParameter {
41      get { return (IResultParameter<DoubleValue>)Parameters["Hypervolume"]; }
42    }
43    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter {
44      get { return (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"]; }
45    }
46    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter {
47      get { return (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"]; }
48    }
[14092]49
[14097]50
[13988]51    [StorableConstructor]
[14108]52    protected HypervolumeAnalyzer(bool deserializing)
53      : base(deserializing) {
[14092]54    }
[13672]55
[14044]56    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
57      : base(original, cloner) {
[13988]58    }
[14044]59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new HypervolumeAnalyzer(this, cloner);
[13988]61    }
[13725]62
[14092]63    public HypervolumeAnalyzer() {
64      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
[14097]65      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
66      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
67      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
68      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
69      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
70      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
71
72
[14092]73    }
[13725]74
[14044]75    public override IOperation Apply() {
76      var qualities = QualitiesParameter.ActualValue;
77      var testFunction = TestFunctionParameter.ActualValue;
[13988]78      int objectives = qualities[0].Length;
[14092]79      var referencePoint = ReferencePointParameter.ActualValue;
[13672]80
[14097]81      double best = BestKnownHypervolumeResultParameter.ActualValue.Value;
82      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
83        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
[13988]84      }
[13672]85
[14081]86      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
[14044]87
[14092]88      double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives));
[14044]89
[14108]90      if (hv > best) {
[14044]91        best = hv;
[13988]92      }
[13672]93
[14097]94      HypervolumeResultParameter.ActualValue.Value = hv;
95      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
96      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
[13936]97
[14044]98      return base.Apply();
[13672]99    }
[14044]100
[13988]101  }
[13672]102}
Note: See TracBrowser for help on using the repository browser.