Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ6.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.8 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    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 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, ((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 g = 0, length = 0;
87      for (int i = objectives; i < r.Length; i++) {
88        g += r[i];
89        length += r[i] * r[i];
90      }
91      length = Math.Sqrt(length);
92      g = 1.0 + 9.0 / length * g;
93
94      //calculating f0...fM-2
95      for (int i = 0; i < objectives - 1; i++) {
96        res[i] = r[i];
97      }
98      //calculate fM-1
99      double h = objectives;
100      for (int i = 0; i < objectives - 1; i++) {
101        h -= res[i] / (1 + g) * (1 + Math.Sin(3 * Math.PI * res[i]));
102      }
103      res[objectives - 1] = (1 + g) * h;
104
105      return res;
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.