Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/DTLZ/DTLZ8.cs @ 15624

Last change on this file since 15624 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 4.2 KB
RevLine 
[13672]1#region License Information
2/* HeuristicLab
[15583]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13672]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;
[13620]22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Encodings.RealVectorEncoding;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
[14111]27namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
[13776]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")]
[13620]29  [StorableClass]
[13776]30  public class DTLZ8 : DTLZ, IConstrainedTestFunction {
[14067]31    public static double[] IllegalValue(int size, bool[] maximization) {
32      double[] res = new double[size];
33      for (int i = 0; i < size; i++) {
34        res[i] = maximization[i] ? Double.MinValue : Double.MaxValue;
35      }
36      return res;
37    }
[13620]38
39    [StorableConstructor]
40    protected DTLZ8(bool deserializing) : base(deserializing) { }
41    protected DTLZ8(DTLZ8 original, Cloner cloner) : base(original, cloner) { }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new DTLZ8(this, cloner);
44    }
45    public DTLZ8() : base() { }
46
[13776]47    public override double[] Evaluate(RealVector r, int objectives) {
48      if (r.Length < 10 * objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than ten times the number of objectives ");
49      double n = r.Length;
50      double M = objectives;
51      double ratio = n / M;
[13620]52      double[] res = new double[objectives];
[13776]53      for (int j = 0; j < objectives; j++) {
54        double sum = 0;
55        for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
56          sum += r[i];
[13620]57        }
[13776]58        sum /= (int)ratio;
59        res[j] = sum;
60      }
61      for (int j = 0; j < M - 1; j++) {
[14068]62        if (res[objectives - 1] + 4 * res[j] - 1 < 0) return IllegalValue(objectives, GetMaximization(objectives));
[13776]63      }
64      double min = Double.PositiveInfinity;
65      for (int i = 0; i < res.Length - 1; i++) {
66        for (int j = 0; j < i; j++) {
67          double d = res[i] + res[j];
68          if (min < d) min = d;
[13672]69        }
[13620]70      }
71
[14068]72      if (2 * res[objectives - 1] + min - 1 < 0) return IllegalValue(objectives, GetMaximization(objectives));
[13620]73      return res;
74    }
75
[13988]76    public double[] CheckConstraints(RealVector r, int objectives) {
[13672]77      if (r.Length < 10 * objectives) throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than ten times the number of objectives ");
[13620]78      double n = r.Length;
79      double M = objectives;
80      double ratio = n / M;
81      double[] res = new double[objectives];
[13776]82      double[] constraints = new double[objectives];
[13672]83      for (int j = 0; j < objectives; j++) {
[13620]84        double sum = 0;
[13672]85        for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {
86          sum += r[i];
[13620]87        }
[13672]88        sum /= (int)ratio;
[13620]89        res[j] = sum;
90      }
[13672]91      for (int j = 0; j < M - 1; j++) {
[13776]92        double d1 = res[objectives - 1] + 4 * res[j] - 1;
93        constraints[j] = d1 < 0 ? -d1 : 0;
[13620]94      }
95      double min = Double.PositiveInfinity;
[13672]96      for (int i = 0; i < res.Length - 1; i++) {
97        for (int j = 0; j < i; j++) {
[13776]98          double d2 = res[i] + res[j];
99          if (min < d2) min = d2;
[13620]100        }
101      }
[13776]102      double d = 2 * res[objectives - 1] + min - 1;
103      constraints[constraints.Length - 1] = d < 0 ? -d : 0;
104      return constraints;
[13620]105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.