Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN1.cs

Last change on this file was 16171, checked in by bwerth, 6 years ago

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

File size: 3.0 KB
RevLine 
[13672]1#region License Information
2/* HeuristicLab
[15583]3 * Copyright (C) 2002-2018 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
21using System;
[13620]22using System.Collections.Generic;
[16171]23using System.Linq;
[13620]24using HeuristicLab.Common;
[13421]25using HeuristicLab.Core;
26using HeuristicLab.Encodings.RealVectorEncoding;
[16171]27using HeuristicLab.Optimization;
[13421]28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
[14111]30namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
[13515]31  [Item("SchafferN1", "Schaffer function N.1 for mulitobjective optimization from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
[13421]32  [StorableClass]
33  public class SchafferN1 : MultiObjectiveTestFunction {
[14068]34    protected override double[,] GetBounds(int objectives) {
[13620]35      return new double[,] { { -1e5, 1e5 } };
[13421]36    }
37
[14068]38    protected override bool[] GetMaximization(int objectives) {
[13620]39      return new bool[2];
[13421]40    }
41
[14068]42    protected override double[] GetReferencePoint(int objectives) {
[13672]43      return new double[] { 1e5, 1e5 };
[13421]44    }
45
[13448]46
[14068]47    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
[14069]48      return ParetoFrontStore.GetParetoFront("Misc.ParetoFronts." + "SchafferN1");
[13448]49    }
50
[14068]51    protected override double GetBestKnownHypervolume(int objectives) {
[16171]52      return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives));
[13515]53    }
54
[13421]55    [StorableConstructor]
56    protected SchafferN1(bool deserializing) : base(deserializing) { }
57    protected SchafferN1(SchafferN1 original, Cloner cloner) : base(original, cloner) { }
58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new SchafferN1(this, cloner);
60    }
61
[13771]62    public SchafferN1() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: 1) { }
[13421]63
[13620]64    public override double[] Evaluate(RealVector r, int objectives) {
65      if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
[13421]66      if (r.Length != 1) return null;
[16171]67      var x = r[0];
[13421]68
69      //objective1
[16171]70      var f0 = x * x;
[13421]71
72      //objective0
[16171]73      var f1 = x - 2;
[13421]74      f1 *= f1;
75
[13620]76      return new double[] { f0, f1 };
[13421]77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.