Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ7.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: 3.1 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("DTLZ7", " http://repository.ias.ac.in/81671/ [30.11.15]")]
16  [StorableClass]
17  public class DTLZ7 : 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 DTLZ7(bool deserializing) : base(deserializing) { }
69    protected DTLZ7(DTLZ7 original, Cloner cloner) : base(original, cloner) { }
70    public DTLZ7() : base() { }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new DTLZ7(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 f0...fM-1;
86      double n = 10 * objectives;
87      for (int i = 0; i < objectives; i++) {
88        double d = 0;
89        for (int j = (int)Math.Floor((i - 1) * n / objectives); j < (int)Math.Floor(i * n / objectives); j++) {
90          d += r[j];
91        }
92        d *= 1 / Math.Floor(n / objectives);
93        res[i] = d;
94      }
95
96      //evaluate constraints g0...gM-2
97      for (int i = 0; i < objectives - 1; i++) {
98        if (res[objectives - 1] + 4 * res[i] - 1 < 0) return null; //TODO null is not the way to go
99      }
100      //evaluate gM-1
101      double min = Double.PositiveInfinity;
102      for (int i = 0; i < objectives - 1; i++) {
103        for (int j = 0; j < i; j++) min = Math.Min(min, res[i] + res[j]);
104      };
105      if (2 * res[objectives - 1] + min - 1 < 0) return null;  //TODO null is not the way to go
106
107      return res;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.