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