Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1087 regorganized testfunctions, added view for qualities

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Encodings.RealVectorEncoding;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
10  [Item("SchafferN2", "Schaffer function N.2 for mulitobjective optimization from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
11  [StorableClass]
12  public class SchafferN2 : MultiObjectiveTestFunction {
13
14    public override double[,] Bounds(int objectives) {
15      return new double[,] { { -5, 10 } };
16    }
17
18    public override bool[] Maximization(int objecitves) {
19      return new bool[2];
20    }
21
22    public override int MinimumSolutionLength {
23      get { return 1; }
24    }
25
26    public override int MaximumSolutionLength {
27      get { return 1; }
28    }
29
30    public override int MinimumObjectives {
31      get { return 2; }
32    }
33
34    public override int MaximumObjectives {
35      get { return 2; }
36    }
37
38    public override double[] ReferencePoint(int objecitves) {
39      return new double[] { 100, 100 };
40    }
41
42
43    public override IEnumerable<double[]> OptimalParetoFront(int objectives) {
44      throw new NotImplementedException();
45    }
46
47    [StorableConstructor]
48    protected SchafferN2(bool deserializing) : base(deserializing) { }
49    protected SchafferN2(SchafferN2 original, Cloner cloner) : base(original, cloner) { }
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new SchafferN2(this, cloner);
52    }
53
54    public SchafferN2() : base() { }
55
56
57
58
59
60    public override double[] Evaluate(RealVector r, int objectives) {
61      if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
62      double x = r[0];
63
64      //objective1
65      double f0;
66      if (x <= 1) f0 = -x;
67      else if (x <= 3) f0 = x - 2;
68      else if (x <= 4) f0 = 4 - x;
69      else f0 = x - 4;
70
71      //objective0
72      double f1 = x - 5;
73      f1 *= f1;
74
75      return new double[] { f0, f1 };
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.