Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/SchafferN2.cs @ 13448

Last change on this file since 13448 was 13448, checked in by bwerth, 8 years ago

#1087 implemented more Testfunctions; enabled setting of SolutionSize

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8using HeuristicLab.Data;
9using HeuristicLab.Encodings.RealVectorEncoding;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.Problems.MultiObjectiveTestFunction;
12
13namespace HeuristicLab.Problems.TestFunctions {
14  [Item("SchafferN2", "from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
15  [StorableClass]
16  public class SchafferN2 : MultiObjectiveTestFunction {
17
18    public override DoubleMatrix Bounds {
19      get {
20        return new DoubleMatrix(new double[,] { { -5, 10 } });
21      }
22    }
23
24    public override bool[] Maximization {
25      get {
26        return new bool[] { false, false };
27      }
28    }
29
30    public override int MaximumProblemSize {
31      get {
32        return 1;
33      }
34    }
35
36    public override int MaximumSolutionSize {
37      get {
38        return 2;
39      }
40    }
41
42    public override int MinimumProblemSize {
43      get {
44        return 1;
45      }
46    }
47
48    public override int MinimumSolutionSize {
49      get {
50        return 2;
51      }
52    }
53
54    public override int ActualSolutionSize {
55      get {
56        return 2;
57      }
58
59      set {
60      }
61    }
62
63    [StorableConstructor]
64    protected SchafferN2(bool deserializing) : base(deserializing) { }
65    protected SchafferN2(SchafferN2 original, Cloner cloner) : base(original, cloner) { }
66    public SchafferN2() : base() { }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new SchafferN2(this, cloner);
70    }
71
72
73
74    public override double[] Evaluate(RealVector r) {
75      double x = r[0];
76
77      //objective1
78      double f0;
79      if (x <= 11) f0 = -x;
80      else if (x <= 3) f0 = x - 2;
81      else if (x <= 4) f0 = 4 - x;
82      else f0 = x - 4;
83
84      //objective0
85      double f1 = x - 5;
86      f1 *= f1;
87
88      return new double[] { f0, f1 };
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.