Free cookie consent management tool by TermsFeed Policy Generator

# source:branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ2.cs@13448

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

#1087 implemented more Testfunctions; enabled setting of SolutionSize

File size: 2.6 KB
Line
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
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        bool[] res = new bool[actualSolutionSize];
39        for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
40        return res;
41      }
42    }
43
44    public override int MaximumProblemSize {
45      get {
46        return int.MaxValue;
47      }
48    }
49
50    public override int MaximumSolutionSize { //TODO ask Michael
51      get {
52        return int.MaxValue;
53      }
54    }
55
56    public override int MinimumProblemSize {
57      get {
58        return Math.Max(2,actualSolutionSize);
59      }
60    }
61
62    public override int MinimumSolutionSize {
63      get {
64        return 2;
65      }
66    }
67
68    [StorableConstructor]
69    protected DTLZ2(bool deserializing) : base(deserializing) { }
70    protected DTLZ2(DTLZ2 original, Cloner cloner) : base(original, cloner) { }
71    public DTLZ2() : base() { }
72
73    public override IDeepCloneable Clone(Cloner cloner) {
74      return new DTLZ2(this, cloner);
75    }
76
77
78
79    public override double[] Evaluate(RealVector r) {
80      return Evaluate(r, actualSolutionSize);
81    }
82
83    private double[] Evaluate(RealVector r, int objectives) {
84      double[] res = new double[objectives];
85
86      //calculate g(Xm)
87      double g = 0;
88      for (int i = objectives; i < r.Length; i++) {
89        double d = r[i] - 0.5;
90        g += d * d;
91      }
92
93      //calculating f0...fM-1
94      for (int i = 0; i < objectives; i++) {
95        double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
96        for (int j = 0; j < objectives - i - 1; j++) {
97          f *= Math.Cos(r[j] * Math.PI / 2);
98        }
99        res[i] = f;
100      }
101      return res;
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.