Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2901_StaticSelectionMethods/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/SchafferN2.cs @ 15778

Last change on this file since 15778 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 2.7 KB
Line 
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
21using System;
22using System.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
29  [Item("SchafferN2", "Schaffer function N.2 for mulitobjective optimization from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
30  [StorableClass]
31  public class SchafferN2 : MultiObjectiveTestFunction {
32    protected override double[,] GetBounds(int objectives) {
33      return new double[,] { { -5, 10 } };
34    }
35
36    protected override bool[] GetMaximization(int objecitves) {
37      return new bool[2];
38    }
39
40    protected override double[] GetReferencePoint(int objecitves) {
41      return new double[] { 100, 100 };
42    }
43
44
45    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
46      return null;
47    }
48
49    [StorableConstructor]
50    protected SchafferN2(bool deserializing) : base(deserializing) { }
51    protected SchafferN2(SchafferN2 original, Cloner cloner) : base(original, cloner) { }
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new SchafferN2(this, cloner);
54    }
55
56    public SchafferN2() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: 1) { }
57
58
59    public override double[] Evaluate(RealVector r, int objectives) {
60      if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
61      double x = r[0];
62
63      //objective1
64      double f0;
65      if (x <= 1) f0 = -x;
66      else if (x <= 3) f0 = x - 2;
67      else if (x <= 4) f0 = 4 - x;
68      else f0 = x - 4;
69
70      //objective0
71      double f1 = x - 5;
72      f1 *= f1;
73
74      return new double[] { f0, f1 };
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.