[13672] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 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 | using System;
|
---|
[13620] | 22 | using System.Collections.Generic;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
[13421] | 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
[14111] | 28 | namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
|
---|
[13515] | 29 | [Item("SchafferN1", "Schaffer function N.1 for mulitobjective optimization from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
|
---|
[13421] | 30 | [StorableClass]
|
---|
| 31 | public class SchafferN1 : MultiObjectiveTestFunction {
|
---|
[14068] | 32 | protected override double[,] GetBounds(int objectives) {
|
---|
[13620] | 33 | return new double[,] { { -1e5, 1e5 } };
|
---|
[13421] | 34 | }
|
---|
| 35 |
|
---|
[14068] | 36 | protected override bool[] GetMaximization(int objectives) {
|
---|
[13620] | 37 | return new bool[2];
|
---|
[13421] | 38 | }
|
---|
| 39 |
|
---|
[14068] | 40 | protected override double[] GetReferencePoint(int objectives) {
|
---|
[13672] | 41 | return new double[] { 1e5, 1e5 };
|
---|
[13421] | 42 | }
|
---|
| 43 |
|
---|
[13448] | 44 |
|
---|
[14068] | 45 | protected override IEnumerable<double[]> GetOptimalParetoFront(int objectives) {
|
---|
[14069] | 46 | return ParetoFrontStore.GetParetoFront("Misc.ParetoFronts." + "SchafferN1");
|
---|
[13448] | 47 | }
|
---|
| 48 |
|
---|
[14068] | 49 | protected override double GetBestKnownHypervolume(int objectives) {
|
---|
| 50 | return Hypervolume.Calculate(GetOptimalParetoFront(objectives), GetReferencePoint(objectives), GetMaximization(objectives));
|
---|
[13515] | 51 | }
|
---|
| 52 |
|
---|
[13421] | 53 | [StorableConstructor]
|
---|
| 54 | protected SchafferN1(bool deserializing) : base(deserializing) { }
|
---|
| 55 | protected SchafferN1(SchafferN1 original, Cloner cloner) : base(original, cloner) { }
|
---|
| 56 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 57 | return new SchafferN1(this, cloner);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[13771] | 60 | public SchafferN1() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: 1) { }
|
---|
[13421] | 61 |
|
---|
[13620] | 62 | public override double[] Evaluate(RealVector r, int objectives) {
|
---|
| 63 | if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
|
---|
[13421] | 64 | if (r.Length != 1) return null;
|
---|
| 65 | double x = r[0];
|
---|
| 66 |
|
---|
| 67 | //objective1
|
---|
| 68 | double f0 = x * x;
|
---|
| 69 |
|
---|
| 70 | //objective0
|
---|
| 71 | double f1 = x - 2;
|
---|
| 72 | f1 *= f1;
|
---|
| 73 |
|
---|
[13620] | 74 | return new double[] { f0, f1 };
|
---|
[13421] | 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|