#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { [StorableClass] [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")] public class HypervolumeAnalyzer : MOTFAnalyzer { public ILookupParameter ReferencePointParameter { get { return (ILookupParameter)Parameters["ReferencePoint"]; } } public IResultParameter HypervolumeResultParameter { get { return (IResultParameter)Parameters["Hypervolume"]; } } public IResultParameter BestKnownHypervolumeResultParameter { get { return (IResultParameter)Parameters["Best known hypervolume"]; } } public IResultParameter HypervolumeDistanceResultParameter { get { return (IResultParameter)Parameters["Absolute Distance to BestKnownHypervolume"]; } } [StorableConstructor] protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { } protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new HypervolumeAnalyzer(this, cloner); } public HypervolumeAnalyzer() { Parameters.Add(new LookupParameter("ReferencePoint", "The reference point for hypervolume calculation")); Parameters.Add(new ResultParameter("Hypervolume", "The hypervolume of the current generation")); Parameters.Add(new ResultParameter("Best known hypervolume", "The optimal hypervolume")); Parameters.Add(new ResultParameter("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume")); HypervolumeResultParameter.DefaultValue = new DoubleValue(0); BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0); HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0); } public override IOperation Apply() { var qualities = QualitiesParameter.ActualValue; var testFunction = TestFunctionParameter.ActualValue; int objectives = qualities[0].Length; var referencePoint = ReferencePointParameter.ActualValue; double best = BestKnownHypervolumeResultParameter.ActualValue.Value; if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) { best = Math.Max(best, testFunction.OptimalHypervolume(objectives)); } IEnumerable front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true); double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives)); if (hv > best) { best = hv; } HypervolumeResultParameter.ActualValue.Value = hv; BestKnownHypervolumeResultParameter.ActualValue.Value = best; HypervolumeDistanceResultParameter.ActualValue.Value = best - hv; return base.Apply(); } } }