Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2520_PersistenceReintegration/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Fonseca.cs @ 16462

Last change on this file since 16462 was 16462, checked in by jkarder, 5 years ago

#2520: worked on reintegration of new persistence

  • added nuget references to HEAL.Fossil
  • added StorableType attributes to many classes
  • changed signature of StorableConstructors
  • removed some classes in old persistence
  • removed some unnecessary usings
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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 HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.RealVectorEncoding;
27using HEAL.Fossil;
28
29namespace 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  [StorableType("CBB43DEB-9DD2-4365-A3CF-18F89F2A47B0")]
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(StorableConstructorFlag _) : base(_) { }
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}
Note: See TracBrowser for help on using the repository browser.