1 | using System;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
|
---|
8 | [Item("DTLZ8", "Testfunction as defined as DTLZ7 in http://repository.ias.ac.in/81671/ [30.11.15]")]
|
---|
9 | [StorableClass]
|
---|
10 | public class DTLZ8 : DTLZ {
|
---|
11 |
|
---|
12 |
|
---|
13 | [StorableConstructor]
|
---|
14 | protected DTLZ8(bool deserializing) : base(deserializing) { }
|
---|
15 | protected DTLZ8(DTLZ8 original, Cloner cloner) : base(original, cloner) { }
|
---|
16 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
17 | return new DTLZ8(this, cloner);
|
---|
18 | }
|
---|
19 | public DTLZ8() : base() { }
|
---|
20 |
|
---|
21 | public double[] Evaluate2(RealVector r, int objectives) {
|
---|
22 | if (r.Length < objectives) {
|
---|
23 | throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to ten times the dimensionality of the solution(SolutionSize) ");
|
---|
24 | }
|
---|
25 | double[] res = new double[objectives];
|
---|
26 |
|
---|
27 | //calculate f0...fM-1;
|
---|
28 | double n = 10 * objectives;
|
---|
29 | for (int i = 1; i <= objectives; i++) {
|
---|
30 | double d = 0;
|
---|
31 | int c = 0;
|
---|
32 | for (int j = (int)Math.Floor((i - 1) * n / objectives); j < Math.Min((int)Math.Floor(i * n / objectives), r.Length); j++) {
|
---|
33 | d += r[j];
|
---|
34 | c++;
|
---|
35 | }
|
---|
36 | if (c != 0) {
|
---|
37 | d *= 1.0 / c;
|
---|
38 | }
|
---|
39 | res[i - 1] = d;
|
---|
40 | }
|
---|
41 |
|
---|
42 | //evaluate constraints g0...gM-2
|
---|
43 | for (int i = 0; i < objectives - 1; i++) {
|
---|
44 | if (res[objectives - 1] + 4 * res[i] - 1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization(objectives));
|
---|
45 | }
|
---|
46 | //evaluate gM-1
|
---|
47 | double min = Double.PositiveInfinity;
|
---|
48 | for (int i = 0; i < objectives - 1; i++) {
|
---|
49 | for (int j = 0; j < i; j++) min = Math.Min(min, res[i] + res[j]);
|
---|
50 | };
|
---|
51 | if (2 * res[objectives - 1] + min - 1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization(objectives));
|
---|
52 |
|
---|
53 | return res;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | public override double[] Evaluate(RealVector r, int objectives) {
|
---|
58 | if (r.Length < 10*objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to ten times the dimensionality of the solution(SolutionSize) ");
|
---|
59 | double n = r.Length;
|
---|
60 | double M = objectives;
|
---|
61 | double ratio = n / M;
|
---|
62 | double[] res = new double[objectives];
|
---|
63 | for(int j =0; j < objectives; j++) {
|
---|
64 | double sum = 0;
|
---|
65 | for(int i = (int) (j*ratio); i < (j+1)+ratio; i++) {
|
---|
66 | sum+=r[i];
|
---|
67 | }
|
---|
68 | sum /= (int) ratio;
|
---|
69 | res[j] = sum;
|
---|
70 | }
|
---|
71 | for(int j = 0; j < M - 1; j++) {
|
---|
72 | if(res[objectives - 1]+4*res[j]-1<0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization(objectives));
|
---|
73 | }
|
---|
74 | double min = Double.PositiveInfinity;
|
---|
75 | for(int i =0; i < res.Length - 1; i++) {
|
---|
76 | for(int j = 0;j< i; j++) {
|
---|
77 | double d = res[i] + res[j];
|
---|
78 | if (min < d) min = d;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (2*res[objectives-1]+min-1<0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization(objectives));
|
---|
83 | return res;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | }
|
---|
88 | }
|
---|