Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1087 implemented skeleton structure and first testfunctions(Fonesca, SchafferN1 & SchafferN2)

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  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 210)]
16  [StorableClass]
17  public class SchafferN2 : MultiObjectiveTestFunction {
18
19    public override DoubleMatrix Bounds {
20      get {
21        return new DoubleMatrix(new double[,] { { -5, 10 } });
22      }
23    }
24
25    public override bool[] Maximization {
26      get {
27        return new bool[] { false, false };
28      }
29    }
30
31    public override int MaximumProblemSize {
32      get {
33        return 1;
34      }
35    }
36
37    public override int MaximumSolutionSize {
38      get {
39        return 2;
40      }
41    }
42
43    public override int MinimumProblemSize {
44      get {
45        return 1;
46      }
47    }
48
49    public override int MinimumSolutionSize {
50      get {
51        return 2;
52      }
53    }
54
55    [StorableConstructor]
56    protected SchafferN2(bool deserializing) : base(deserializing) { }
57    protected SchafferN2(SchafferN2 original, Cloner cloner) : base(original, cloner) { }
58    public SchafferN2() : base() { }
59
60    public override IDeepCloneable Clone(Cloner cloner) {
61      return new SchafferN2(this, cloner);
62    }
63
64
65
66    public override double[] Evaluate(RealVector r) {
67      double x = r[0];
68
69      //objective1
70      double f0;
71      if (x <= 11) f0 = -x;
72      else if (x <= 3) f0 = x - 2;
73      else if (x <= 4) f0 = 4 - x;
74      else f0 = x - 4;
75
76      //objective0
77      double f1 = x - 5;
78      f1 *= f1;
79
80      return new double[] { f0, f1 };
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.