Free cookie consent management tool by TermsFeed Policy Generator

# source:branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ1.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;
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("DTLZ1", " http://repository.ias.ac.in/81671/ [30.11.15]")]
16  [StorableClass]
17  public class DTLZ1 : 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 {
51      get {
52
53        return int.MaxValue;
54      }
55    }
56
57    public override int MinimumProblemSize {
58      get {
59        return Math.Max(2, ActualSolutionSize+1);
60      }
61    }
62
63    public override int MinimumSolutionSize {
64      get {
65        return 2;
66      }
67    }
68
69    [StorableConstructor]
70    protected DTLZ1(bool deserializing) : base(deserializing) { }
71    protected DTLZ1(DTLZ1 original, Cloner cloner) : base(original, cloner) {}
72    public DTLZ1() : base() {
73    }
74
75    public override IDeepCloneable Clone(Cloner cloner) {
76      return new DTLZ1(this, cloner);
77    }
78
79
80
81    public override double[] Evaluate(RealVector r) {
82      return Evaluate(r, actualSolutionSize);
83    }
84
85    private double[] Evaluate(RealVector r, int objectives) {
86      double[] res = new double[objectives];
87
88      //calculate g(Xm)
89      double sum = 0, length = 0;
90      for (int i = objectives; i < r.Length; i++) {
91        double d = r[i] - 0.5;
92        sum += d * d - Math.Cos(20 * Math.PI * d);
93        length += r[i] * r[i];
94      }
95      length = Math.Sqrt(length);
96      double g = 100 * (length + sum);
97
98      //calculating f0...fM-1
99      for (int i = 0; i < objectives; i++) {
100        double f = 0.5 * i == 0 ? 1 : (1 - r[objectives - i - 1]) * (1 + g);
101        for (int j = 0; j < objectives - i - 1; j++) {
102          f *= r[j];
103        }
104        res[i] = f;
105      }
106      return res;
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.