1  #region License Information


2  /* HeuristicLab


3  * Copyright (C) 20022019 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


21  using System;


22  using HeuristicLab.Common;


23  using HeuristicLab.Core;


24  using HeuristicLab.Encodings.RealVectorEncoding;


25  using HEAL.Fossil;


26 


27  namespace HeuristicLab.Problems.TestFunctions.MultiObjective {


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  [StorableType("067D6CD204164FB3AA21B561776762A4")]


30  public class DTLZ8 : DTLZ, IConstrainedTestFunction {


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  }


38 


39  [StorableConstructor]


40  protected DTLZ8(StorableConstructorFlag _) : base(_) { }


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 


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;


52  double[] res = new double[objectives];


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];


57  }


58  sum /= (int)ratio;


59  res[j] = sum;


60  }


61  for (int j = 0; j < M  1; j++) {


62  if (res[objectives  1] + 4 * res[j]  1 < 0) return IllegalValue(objectives, GetMaximization(objectives));


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;


69  }


70  }


71 


72  if (2 * res[objectives  1] + min  1 < 0) return IllegalValue(objectives, GetMaximization(objectives));


73  return res;


74  }


75 


76  public double[] CheckConstraints(RealVector r, int objectives) {


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 ");


78  double n = r.Length;


79  double M = objectives;


80  double ratio = n / M;


81  double[] res = new double[objectives];


82  double[] constraints = new double[objectives];


83  for (int j = 0; j < objectives; j++) {


84  double sum = 0;


85  for (int i = (int)(j * ratio); i < (j + 1) + ratio; i++) {


86  sum += r[i];


87  }


88  sum /= (int)ratio;


89  res[j] = sum;


90  }


91  for (int j = 0; j < M  1; j++) {


92  double d1 = res[objectives  1] + 4 * res[j]  1;


93  constraints[j] = d1 < 0 ? d1 : 0;


94  }


95  double min = Double.PositiveInfinity;


96  for (int i = 0; i < res.Length  1; i++) {


97  for (int j = 0; j < i; j++) {


98  double d2 = res[i] + res[j];


99  if (min < d2) min = d2;


100  }


101  }


102  double d = 2 * res[objectives  1] + min  1;


103  constraints[constraints.Length  1] = d < 0 ? d : 0;


104  return constraints;


105  }


106  }


107  }

