Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Fonseca.cs @ 16171

Last change on this file since 16171 was 16171, checked in by bwerth, 6 years ago

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.RealVectorEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
32  [Item("Fonseca", "Fonseca and Flemming function from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
33  [StorableClass]
34  public class Fonseca : MultiObjectiveTestFunction {
35    protected override double[,] GetBounds(int objectives) {
36      return new double[,] { { -4, 4 } };
37    }
38
39    protected override bool[] GetMaximization(int objecitves) {
40      return new bool[2];
41    }
42
43    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
44      return ParetoFrontStore.GetParetoFront("Misc.ParetoFronts." + this.ItemName);
45    }
46
47    protected override double GetBestKnownHypervolume(int objectives) {
48      return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives));
49    }
50
51    protected override double[] GetReferencePoint(int objectives) {
52      return new double[] { 11, 11 };
53    }
54
55    [StorableConstructor]
56    protected Fonseca(bool deserializing) : base(deserializing) { }
57    protected Fonseca(Fonseca original, Cloner cloner) : base(original, cloner) { }
58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new Fonseca(this, cloner);
60    }
61    public Fonseca() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: int.MaxValue) { }
62
63
64    public override double[] Evaluate(RealVector r, int objectives) {
65      if (objectives != 2) throw new ArgumentException("The Fonseca problem must always have 2 objectives");
66      double f0 = 0.0, aux = 1.0 / Math.Sqrt(r.Length);
67
68      //objective1
69      for (var i = 0; i < r.Length; i++) {
70        var d = r[i] - aux;
71        f0 += d * d;
72      }
73      f0 = 1 - Math.Exp(-f0);
74
75      //objective2
76      var f1 = 0.0;
77      for (var i = 0; i < r.Length; i++) {
78        var d = r[i] + aux;
79        f1 += d * d;
80      }
81      f1 = 1 - Math.Exp(-f1);
82
83      double[] res = { f0, f1 };
84      return res;
85    }
86
87  }
88}
Note: See TracBrowser for help on using the repository browser.