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 | using System;
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
|
---|
29 | [Item("SchafferN1", "Schaffer function N.1 for mulitobjective optimization from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
|
---|
30 | [StorableClass]
|
---|
31 | public class SchafferN1 : MultiObjectiveTestFunction {
|
---|
32 |
|
---|
33 | public override double[,] Bounds(int objectives) {
|
---|
34 | return new double[,] { { -1e5, 1e5 } };
|
---|
35 | }
|
---|
36 |
|
---|
37 | public override bool[] Maximization(int objecitves) {
|
---|
38 | return new bool[2];
|
---|
39 | }
|
---|
40 |
|
---|
41 | public override int MinimumSolutionLength {
|
---|
42 | get { return 1; }
|
---|
43 | }
|
---|
44 | public override int MaximumSolutionLength {
|
---|
45 | get { return 1; }
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | public override int MinimumObjectives {
|
---|
50 | get { return 2; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public override int MaximumObjectives {
|
---|
54 | get { return 2; }
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | public override double[] ReferencePoint(int objecitves) {
|
---|
59 | return new double[] { 1e5, 1e5 };
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | public override IEnumerable<double[]> OptimalParetoFront(int objecitves) {
|
---|
64 | return PFStore.get("Schaffer");
|
---|
65 | }
|
---|
66 | public override double BestKnownHypervolume(int objectives) {
|
---|
67 | return Hypervolume.Calculate(OptimalParetoFront(objectives), ReferencePoint(objectives), Maximization(objectives));
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | [StorableConstructor]
|
---|
72 | protected SchafferN1(bool deserializing) : base(deserializing) { }
|
---|
73 | protected SchafferN1(SchafferN1 original, Cloner cloner) : base(original, cloner) { }
|
---|
74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new SchafferN1(this, cloner);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public SchafferN1() : base(minimumObjectives: 2, maximumObjectives: 2, minimumSolutionLength: 1, maximumSolutionLength: 1) { }
|
---|
79 |
|
---|
80 | public override double[] Evaluate(RealVector r, int objectives) {
|
---|
81 | if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
|
---|
82 | if (r.Length != 1) return null;
|
---|
83 | double x = r[0];
|
---|
84 |
|
---|
85 | //objective1
|
---|
86 | double f0 = x * x;
|
---|
87 |
|
---|
88 | //objective0
|
---|
89 | double f1 = x - 2;
|
---|
90 | f1 *= f1;
|
---|
91 |
|
---|
92 | return new double[] { f0, f1 };
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|