Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ3.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.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("DTLZ3", " http://repository.ias.ac.in/81671/ [30.11.15]")]
16  [StorableClass]
17  public class DTLZ3 : MultiObjectiveTestFunction {
18
19    public override DoubleMatrix Bounds {
20      get {
21        return new DoubleMatrix(new double[,] { { 0, 1 } });
22      }
23    }
24
25    public override bool[] Maximization {
26      get {
27        bool[] res = new bool[((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value];
28        for(int i =0; i < res.Length; i++)  res[i] = false; //TODO: diligent initialzation
29        return res;
30      }
31    }
32
33    public override int MaximumProblemSize {
34      get {
35        return int.MaxValue;
36      }
37    }
38
39    public override int MaximumSolutionSize { //TODO ask Michael
40      get {
41        return ((ValueParameter<IntValue>)Parameters["ProblemSize"]).Value.Value;
42      }
43    }
44
45    public override int MinimumProblemSize {
46      get {
47        return 2;
48      }
49    }
50
51    public override int MinimumSolutionSize {
52      get {
53        return 2;
54      }
55    }
56
57    public override int ActualSolutionSize {
58      get {
59        throw new NotImplementedException();
60      }
61
62      set {
63        throw new NotImplementedException();
64      }
65    }
66
67    [StorableConstructor]
68    protected DTLZ3(bool deserializing) : base(deserializing) { }
69    protected DTLZ3(DTLZ3 original, Cloner cloner) : base(original, cloner) { }
70    public DTLZ3() : base() { }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new DTLZ3(this, cloner);
74    }
75
76
77
78    public override double[] Evaluate(RealVector r) {
79      return Evaluate(r, ((ValueParameter<IntValue>)Parameters["SolutionSize"]).Value.Value);
80    }
81
82    private double[] Evaluate(RealVector r, int objectives) {
83      double[] res = new double[objectives];
84
85      //calculate g(Xm)
86      double sum = 0, length = 0;
87      for (int i = objectives; i < r.Length; i++) {
88        double d = r[i] - 0.5;
89        sum += d * d - Math.Cos(20 * Math.PI * d);
90        length += r[i] * r[i];
91      }
92      length = Math.Sqrt(length);
93      double g = 100 * (length + sum);
94
95      //calculating f0...fM-1
96      for (int i = 0; i < objectives; i++) {
97        double f = i == 0 ? 1 : (Math.Sin(r[objectives - i - 1] * Math.PI / 2)) * (1 + g);
98        for (int j = 0; j < objectives - i - 1; j++) {
99          f *= Math.Cos(r[j] * Math.PI / 2);
100        }
101        res[i] = f;
102      }
103      return res;
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.