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("DTLZ7", " http://repository.ias.ac.in/81671/ [30.11.15]")]


16  [StorableClass]


17  public class DTLZ7 : 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*10);


58  }


59  }


60 


61  public override int MinimumSolutionSize {


62  get {


63  return 2;


64  }


65  }


66 


67  [StorableConstructor]


68  protected DTLZ7(bool deserializing) : base(deserializing) { }


69  protected DTLZ7(DTLZ7 original, Cloner cloner) : base(original, cloner) { }


70  public DTLZ7() : base() { }


71 


72  public override IDeepCloneable Clone(Cloner cloner) {


73  return new DTLZ7(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 ten times the dimensionality of the solution(SolutionSize) ");


85  }


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


87 


88  //calculate f0...fM1;


89  double n = 10 * objectives;


90  for (int i = 1; i <= objectives; i++) {


91  double d = 0;


92  int c = 0;


93  for (int j = (int)Math.Floor((i  1) * n / objectives); j < Math.Min((int)Math.Floor(i * n / objectives), r.Length); j++) {


94  d += r[j];


95  c++;


96  }


97  d *= 1.0 / c;


98  res[i1] = d;


99  }


100 


101  //evaluate constraints g0...gM2


102  for (int i = 0; i < objectives  1; i++) {


103  if (res[objectives  1] + 4 * res[i]  1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives,Maximization);


104  }


105  //evaluate gM1


106  double min = Double.PositiveInfinity;


107  for (int i = 0; i < objectives  1; i++) {


108  for (int j = 0; j < i; j++) min = Math.Min(min, res[i] + res[j]);


109  };


110  if (2 * res[objectives  1] + min  1 < 0) return MultiObjectiveTestFunction.IllegalValue(objectives, Maximization);


111 


112  return res;


113  }


114  }


115  }

