1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HEAL.Attic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Analysis {
|
---|
31 | [StorableType("fc42ed56-15de-41df-bf59-0e5b11cd4f9b")]
|
---|
32 | [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
|
---|
33 | public class HypervolumeAnalyzer : MultiObjectiveSuccessAnalyzer {
|
---|
34 | public override string ResultName {
|
---|
35 | get { return "Hypervolume"; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public ILookupParameter<DoubleArray> ReferencePointParameter {
|
---|
39 | get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter {
|
---|
43 | get { return (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"]; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter {
|
---|
47 | get { return (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"]; }
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | [StorableConstructor]
|
---|
52 | protected HypervolumeAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
53 |
|
---|
54 | protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
55 |
|
---|
56 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
57 | return new HypervolumeAnalyzer(this, cloner);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public HypervolumeAnalyzer() {
|
---|
61 | Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
|
---|
62 | Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation", "Results", new DoubleValue(double.NaN)));
|
---|
63 | Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
|
---|
64 | Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
|
---|
65 | BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(double.NaN);
|
---|
66 | HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(double.NaN);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override IOperation Apply() {
|
---|
70 | var qualities = QualitiesParameter.ActualValue.Select(x => x.CloneAsArray()).ToArray();
|
---|
71 | var referencePoint = ReferencePointParameter.ActualValue.ToArray();
|
---|
72 | var best = BestKnownHypervolumeResultParameter.ActualValue.Value;
|
---|
73 | var maximization = MaximizationParameter.ActualValue.ToArray();
|
---|
74 |
|
---|
75 | var hv = HypervolumeCalculator.CalculateHypervolume(qualities, referencePoint, maximization);
|
---|
76 | if (hv > best || double.IsNaN(best)) best = hv;
|
---|
77 | ResultParameter.ActualValue.Value = hv;
|
---|
78 | BestKnownHypervolumeResultParameter.ActualValue.Value = best;
|
---|
79 | HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
|
---|
80 |
|
---|
81 | return base.Apply();
|
---|
82 | }
|
---|
83 | }
|
---|
84 | } |
---|