Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2520: updated year of copyrights

File size: 3.1 KB
RevLine 
[13672]1#region License Information
2/* HeuristicLab
[16453]3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13672]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;
[13620]23using System.Collections.Generic;
[13421]24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.RealVectorEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
[14111]29namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
[13515]30  [Item("Fonseca", "Fonseca and Flemming function from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
[13421]31  [StorableClass]
32  public class Fonseca : MultiObjectiveTestFunction {
[14068]33    protected override double[,] GetBounds(int objectives) {
[13672]34      return new double[,] { { -4, 4 } };
[13421]35    }
36
[14068]37    protected override bool[] GetMaximization(int objecitves) {
[13620]38      return new bool[2];
[13421]39    }
40
[14068]41    protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
[14069]42      return ParetoFrontStore.GetParetoFront("Misc.ParetoFronts." + this.ItemName);
[13448]43    }
[14068]44
45    protected override double GetBestKnownHypervolume(int objectives) {
46      return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
[13620]47    }
[13448]48
[14068]49    protected override double[] GetReferencePoint(int objectives) {
[13620]50      return new double[] { 11, 11 };
[13515]51    }
52
[13421]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    }
[14067]59    public Fonseca() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: int.MaxValue) { }
[13421]60
61
[13620]62    public override double[] Evaluate(RealVector r, int objectives) {
63      if (objectives != 2) throw new ArgumentException("The Fonseca problem must always have 2 objectives");
[13421]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    }
[13620]84
[13421]85  }
86}
Note: See TracBrowser for help on using the repository browser.