Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/Fonseca.cs @ 14067

Last change on this file since 14067 was 14067, checked in by mkommend, 8 years ago

#1087: Refactored multi-objective test functions.

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
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
34    public override double[,] Bounds(int objectives) {
35      return new double[,] { { -4, 4 } };
36    }
37
38    public override bool[] Maximization(int objecitves) {
39      return new bool[2];
40    }
41
42    public override IEnumerable<double[]> OptimalParetoFront(int objectives) {
43      return PFStore.get(this.ItemName);
44    }
45    public override double BestKnownHypervolume(int objectives) {
46      return Hypervolume.Calculate(OptimalParetoFront(objectives), ReferencePoint(objectives), Maximization(objectives));
47    }
48
49    public override double[] ReferencePoint(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}
Note: See TracBrowser for help on using the repository browser.