Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/Misc/Kursawe.cs @ 17709

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

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

File size: 3.1 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
21using System;
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.RealVectorEncoding;
27using HeuristicLab.Optimization;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
31  [Item("Kursawe", "Kursawe function from // http://darwin.di.uminho.pt/jecoli/index.php/Multiobjective_example [30.11.2015]")]
32  [StorableClass]
33  public class Kursawe : MultiObjectiveTestFunction {
34    protected override double[,] GetBounds(int objectives) {
35      return new double[,] { { -5, 5 } };
36    }
37
38    protected override bool[] GetMaximization(int objecitves) {
39      return new bool[2];
40    }
41
42    protected override IEnumerable<double[]> GetOptimalParetoFront(int objecitves) {
43      return ParetoFrontStore.GetParetoFront("Misc.ParetoFronts." + this.ItemName);
44    }
45
46    protected override double GetBestKnownHypervolume(int objectives) {
47      return HypervolumeCalculator.CalculateHypervolume(GetOptimalParetoFront(objectives).ToArray(), GetReferencePoint(objectives), GetMaximization(objectives));
48    }
49
50    protected override double[] GetReferencePoint(int objectives) {
51      return new double[] { 11, 11 };
52    }
53
54    [StorableConstructor]
55    protected Kursawe(bool deserializing) : base(deserializing) { }
56    protected Kursawe(Kursawe original, Cloner cloner) : base(original, cloner) { }
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new Kursawe(this, cloner);
59    }
60    public Kursawe() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 3, maximumSolutionLength: int.MaxValue) { }
61
62
63
64
65
66    public override double[] Evaluate(RealVector r, int objectives) {
67      if (objectives != 2) throw new ArgumentException("The Kursawe problem must always have 2 objectives");
68      //objective 1
69      var f0 = 0.0;
70      for (var i = 0; i < r.Length - 1; i++) {
71        f0 += -10 * Math.Exp(-0.2 * Math.Sqrt(r[i] * r[i] + r[i + 1] * r[i + 1]));
72      }
73      //objective2
74      var f1 = 0.0;
75      for (var i = 0; i < r.Length; i++) {
76        f1 += Math.Pow(Math.Abs(r[i]), 0.8) + 5 * Math.Sin(Math.Pow(r[i], 3));
77      }
78
79      return new double[] { f0, f1 };
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.