1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
10 | using HeuristicLab.Parameters;
|
---|
11 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
12 | using HeuristicLab.Problems.MultiObjectiveTestFunction;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Problems.TestFunctions {
|
---|
15 | [Item("DTLZ6", " http://repository.ias.ac.in/81671/ [30.11.15]")]
|
---|
16 | [StorableClass]
|
---|
17 | public class DTLZ6 : 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 | return new bool[actualSolutionSize];
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override int MaximumProblemSize {
|
---|
43 | get {
|
---|
44 | return int.MaxValue;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public override int MaximumSolutionSize {
|
---|
49 | get {
|
---|
50 |
|
---|
51 | return int.MaxValue;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public override int MinimumProblemSize {
|
---|
56 | get {
|
---|
57 | return Math.Max(2, ActualSolutionSize);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override int MinimumSolutionSize {
|
---|
62 | get {
|
---|
63 | return 2;
|
---|
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, ActualSolutionSize);
|
---|
80 | }
|
---|
81 |
|
---|
82 | private double[] Evaluate(RealVector r, int objectives) {
|
---|
83 | if (r.Length < objectives) {
|
---|
84 | throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to the dimensionality of the solution(SolutionSize) ");
|
---|
85 | }
|
---|
86 | double[] res = new double[objectives];
|
---|
87 |
|
---|
88 | //calculate g(Xm)
|
---|
89 | double g = 0, length = 0;
|
---|
90 | for (int i = objectives; i < r.Length; i++) {
|
---|
91 | g += r[i];
|
---|
92 | length += r[i] * r[i];
|
---|
93 | }
|
---|
94 | length = Math.Sqrt(length);
|
---|
95 | g = 1.0 + 9.0 / length * g;
|
---|
96 | if (length == 0) { g = 1; }
|
---|
97 |
|
---|
98 | //calculating f0...fM-2
|
---|
99 | for (int i = 0; i < objectives - 1; i++) {
|
---|
100 | res[i] = r[i];
|
---|
101 | }
|
---|
102 | //calculate fM-1
|
---|
103 | double h = objectives;
|
---|
104 | for (int i = 0; i < objectives - 1; i++) {
|
---|
105 | h -= res[i] / (1 + g) * (1 + Math.Sin(3 * Math.PI * res[i]));
|
---|
106 | }
|
---|
107 | res[objectives - 1] = (1 + g) * h;
|
---|
108 |
|
---|
109 | return res;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|