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 


22  using System;


23  using System.Collections.Generic;


24  using HeuristicLab.Common;


25  using HeuristicLab.Core;


26  using HeuristicLab.Encodings.RealVectorEncoding;


27  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;


28 


29  namespace HeuristicLab.Problems.TestFunctions.MultiObjective {


30  [Item("Fonseca", "Fonseca and Flemming function from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]


31  [StorableClass]


32  public class Fonseca : MultiObjectiveTestFunction {


33  protected override double[,] GetBounds(int objectives) {


34  return new double[,] { { 4, 4 } };


35  }


36 


37  protected override bool[] GetMaximization(int objecitves) {


38  return new bool[2];


39  }


40 


41  protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {


42  return ParetoFrontStore.GetParetoFront("Misc.ParetoFronts." + this.ItemName);


43  }


44 


45  protected override double GetBestKnownHypervolume(int objectives) {


46  return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));


47  }


48 


49  protected override double[] GetReferencePoint(int objectives) {


50  return new double[] { 11, 11 };


51  }


52 


53  [StorableConstructor]


54  protected Fonseca(bool deserializing) : base(deserializing) { }


55  protected Fonseca(Fonseca original, Cloner cloner) : base(original, cloner) { }


56  public override IDeepCloneable Clone(Cloner cloner) {


57  return new Fonseca(this, cloner);


58  }


59  public Fonseca() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: int.MaxValue) { }


60 


61 


62  public override double[] Evaluate(RealVector r, int objectives) {


63  if (objectives != 2) throw new ArgumentException("The Fonseca problem must always have 2 objectives");


64  double f0 = 0.0, aux = 1.0 / Math.Sqrt(r.Length);


65 


66  //objective1


67  for (int i = 0; i < r.Length; i++) {


68  double d = r[i]  aux;


69  f0 += d * d;


70  }


71  f0 = 1  Math.Exp(f0);


72 


73  //objective2


74  double f1 = 0.0;


75  for (int i = 0; i < r.Length; i++) {


76  double d = r[i] + aux;


77  f1 += d * d;


78  }


79  f1 = 1  Math.Exp(f1);


80 


81  double[] res = { f0, f1 };


82  return res;


83  }


84 


85  }


86  }

