Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/HypervolumeAnalyzer.cs @ 18040

Last change on this file since 18040 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 4.2 KB
RevLine 
[13672]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) 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;
[16565]30using HEAL.Attic;
[13672]31
[14111]32namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
[16565]33  [StorableType("13D363E4-76FF-4A5A-9B2C-767D9E880E4B")]
[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]
[16565]52    protected HypervolumeAnalyzer(StorableConstructorFlag _) : base(_) {
[14092]53    }
[13672]54
[14044]55    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
56      : base(original, cloner) {
[13988]57    }
[14044]58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new HypervolumeAnalyzer(this, cloner);
[13988]60    }
[13725]61
[14092]62    public HypervolumeAnalyzer() {
63      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
[14097]64      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
65      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
66      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
67      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
68      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
69      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
70
71
[14092]72    }
[13725]73
[14044]74    public override IOperation Apply() {
75      var qualities = QualitiesParameter.ActualValue;
76      var testFunction = TestFunctionParameter.ActualValue;
[13988]77      int objectives = qualities[0].Length;
[14092]78      var referencePoint = ReferencePointParameter.ActualValue;
[13672]79
[14097]80      double best = BestKnownHypervolumeResultParameter.ActualValue.Value;
81      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
82        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
[13988]83      }
[13672]84
[14081]85      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
[14044]86
[14092]87      double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives));
[14044]88
[14108]89      if (hv > best) {
[14044]90        best = hv;
[13988]91      }
[13672]92
[14097]93      HypervolumeResultParameter.ActualValue.Value = hv;
94      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
95      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
[13936]96
[14044]97      return base.Apply();
[13672]98    }
[14044]99
[13988]100  }
[13672]101}
Note: See TracBrowser for help on using the repository browser.