Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ6.cs @ 13451

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

#1087 extensive testing; fixed minor bugs

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