Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN1.cs @ 17225

Last change on this file since 17225 was 17225, checked in by mkommend, 5 years ago

#2521: Integrated changes of #2943 into problem refactoring branch.

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