Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ8.cs @ 13988

Last change on this file since 13988 was 13988, checked in by bwerth, 8 years ago

#1087 moved project bugfixes

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21using System;
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Encodings.RealVectorEncoding;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
28  [Item("DTLZ8", "Testfunction as defined as DTLZ7 in http://repository.ias.ac.in/81671/ [30.11.15]. There has been a renumbering therefore the numbers do not match")]
29  [StorableClass]
30  public class DTLZ8 : DTLZ, IConstrainedTestFunction {
31
32    [StorableConstructor]
33    protected DTLZ8(bool deserializing) : base(deserializing) { }
34    protected DTLZ8(DTLZ8 original, Cloner cloner) : base(original, cloner) { }
35    public override IDeepCloneable Clone(Cloner cloner) {
36      return new DTLZ8(this, cloner);
37    }
38    public DTLZ8() : base() { }
39
40    public override double[] Evaluate(RealVector r, int objectives) {
41      if (r.Length < 10 * objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than ten times the number of objectives ");
42      double n = r.Length;
43      double M = objectives;
44      double ratio = n / M;
45      double[] res = new double[objectives];
46      for (int j = 0; j < objectives; j++) {
47        double sum = 0;
48        for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
49          sum += r[i];
50        }
51        sum /= (int)ratio;
52        res[j] = sum;
53      }
54      for (int j = 0; j < M - 1; j++) {
55        if (res[objectives - 1] + 4 * res[j] - 1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization(objectives));
56      }
57      double min = Double.PositiveInfinity;
58      for (int i = 0; i < res.Length - 1; i++) {
59        for (int j = 0; j < i; j++) {
60          double d = res[i] + res[j];
61          if (min < d) min = d;
62        }
63      }
64
65      if (2 * res[objectives - 1] + min - 1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization(objectives));
66      return res;
67    }
68
69    public double[] CheckConstraints(RealVector r, int objectives) {
70      if (r.Length < 10 * objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than ten times the number of objectives ");
71      double n = r.Length;
72      double M = objectives;
73      double ratio = n / M;
74      double[] res = new double[objectives];
75      double[] constraints = new double[objectives];
76      for (int j = 0; j < objectives; j++) {
77        double sum = 0;
78        for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
79          sum += r[i];
80        }
81        sum /= (int)ratio;
82        res[j] = sum;
83      }
84      for (int j = 0; j < M - 1; j++) {
85        double d1 = res[objectives - 1] + 4 * res[j] - 1;
86        constraints[j] = d1 < 0 ? -d1 : 0;
87      }
88      double min = Double.PositiveInfinity;
89      for (int i = 0; i < res.Length - 1; i++) {
90        for (int j = 0; j < i; j++) {
91          double d2 = res[i] + res[j];
92          if (min < d2) min = d2;
93        }
94      }
95      double d = 2 * res[objectives - 1] + min - 1;
96      constraints[constraints.Length - 1] = d < 0 ? -d : 0;
97      return constraints;
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.