Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ2.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.7 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("DTLZ2", " http://repository.ias.ac.in/81671/ [30.11.15]")]
16  [StorableClass]
17  public class DTLZ2 : 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 DTLZ2(bool deserializing) : base(deserializing) { }
69    protected DTLZ2(DTLZ2 original, Cloner cloner) : base(original, cloner) { }
70    public DTLZ2() : base() { }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new DTLZ2(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 or equal than the dimensionality of the solution(SolutionSize) ");
85      }
86
87      double[] res = new double[objectives];
88
89      //calculate g(Xm)
90      double g = 0;
91      for (int i = objectives; i < r.Length; i++) {
92        double d = r[i] - 0.5;
93        g += d * d;
94      }
95
96      //calculating f0...fM-1
97      for (int i = 0; i < objectives; i++) {
98        double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
99        for (int j = 0; j < objectives - i - 1; j++) {
100          f *= Math.Cos(r[j] * Math.PI / 2);
101        }
102        res[i] = f;
103      }
104      return res;
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.