Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ3.cs @ 13515

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

#1087 minor bugfixes and added unittests

File size: 3.1 KB
Line 
1using System;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.RealVectorEncoding;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7
8namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
9  [Item("DTLZ3", "Testfunction as defined as DTLZ3 in http://repository.ias.ac.in/81671/ [30.11.15]")]
10  [StorableClass]
11  public class DTLZ3 : MultiObjectiveTestFunction {
12
13    private int actualSolutionSize = 2;
14    public override int ActualSolutionSize {
15      get {
16        return actualSolutionSize;
17      }
18
19      set {
20        actualSolutionSize = value;
21      }
22    }
23
24    public override DoubleMatrix Bounds {
25      get {
26        return new DoubleMatrix(new double[,] { { 0, 1 } });
27      }
28    }
29
30    public override bool[] Maximization {
31      get {
32        return new bool[actualSolutionSize];
33      }
34    }
35
36    public override int MaximumProblemSize {
37      get {
38        return int.MaxValue;
39      }
40    }
41
42    public override int MaximumSolutionSize {
43      get {
44
45        return int.MaxValue;
46      }
47    }
48
49    public override int MinimumProblemSize {
50      get {
51        return Math.Max(2, ActualSolutionSize);
52      }
53    }
54
55    public override int MinimumSolutionSize {
56      get {
57        return 2;
58      }
59    }
60
61    public override RealVector[] OptimalParetoFront {
62      get {
63        throw new NotImplementedException();
64      }
65    }
66
67    public override RealVector ReferencePoint {
68      get { return new RealVector(new double[] { 11.0, 11.0 }); }
69    }
70
71    public override double BestKnownHypervolume {
72      get { return 121.0 - 1.0 / 4.0 * Math.PI; }
73    }
74
75    [StorableConstructor]
76    protected DTLZ3(bool deserializing) : base(deserializing) { }
77    protected DTLZ3(DTLZ3 original, Cloner cloner) : base(original, cloner) { }
78    public DTLZ3() : base() { }
79
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new DTLZ3(this, cloner);
82    }
83
84
85
86    public override double[] Evaluate(RealVector r) {
87      return Evaluate(r, ActualSolutionSize);
88    }
89
90    private double[] Evaluate(RealVector r, int objectives) {
91      if (r.Length < objectives) {
92        throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize) ");
93      }
94      double[] res = new double[objectives];
95
96      //calculate g(Xm)
97      double sum = 0, length = 0;
98      for (int i = objectives; i < r.Length; i++) {
99        double d = r[i] - 0.5;
100        sum += d * d - Math.Cos(20 * Math.PI * d);
101        length += r[i] * r[i];
102      }
103      length = Math.Sqrt(length);
104      double g = 100 * (length + sum);
105
106      //calculating f0...fM-1
107      for (int i = 0; i < objectives; i++) {
108        double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
109        for (int j = 0; j < objectives - i - 1; j++) {
110          f *= Math.Cos(r[j] * Math.PI / 2);
111        }
112        res[i] = f;
113      }
114      return res;
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.