[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] | 22 | using System;
|
---|
[13672] | 23 | using System.Collections.Generic;
|
---|
[14030] | 24 | using System.Linq;
|
---|
[13672] | 25 | using HeuristicLab.Common;
|
---|
[13725] | 26 | using HeuristicLab.Core;
|
---|
[13672] | 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
[13725] | 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[13672] | 31 |
|
---|
[13988] | 32 | namespace 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 | }
|
---|