1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
|
---|
10 | [Item("SchafferN1", "Schaffer function N.1 for mulitobjective optimization from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
|
---|
11 | [StorableClass]
|
---|
12 | public class SchafferN1 : MultiObjectiveTestFunction {
|
---|
13 |
|
---|
14 | public override double[,] Bounds(int objectives) {
|
---|
15 | return new double[,] { { -1e5, 1e5 } };
|
---|
16 | }
|
---|
17 |
|
---|
18 | public override bool[] Maximization(int objecitves) {
|
---|
19 | return new bool[2];
|
---|
20 | }
|
---|
21 |
|
---|
22 | public override int MinimumSolutionLength {
|
---|
23 | get { return 1; }
|
---|
24 | }
|
---|
25 | public override int MaximumSolutionLength {
|
---|
26 | get { return 1; }
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | public override int MinimumObjectives {
|
---|
31 | get { return 2; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public override int MaximumObjectives {
|
---|
35 | get { return 2; }
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | public override double[] ReferencePoint(int objecitves) {
|
---|
40 | return new double[] { 1e5, 1e5 };
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | public override IEnumerable<double[]> OptimalParetoFront(int objecitves) {
|
---|
45 | return PFStore.get("Schaffer");
|
---|
46 | }
|
---|
47 | public override double BestKnownHypervolume(int objecitves) {
|
---|
48 | return new Hypervolume(ReferencePoint(objecitves), Maximization(2)).GetHypervolume(OptimalParetoFront(objecitves));
|
---|
49 |
|
---|
50 | }
|
---|
51 |
|
---|
52 | [StorableConstructor]
|
---|
53 | protected SchafferN1(bool deserializing) : base(deserializing) { }
|
---|
54 | protected SchafferN1(SchafferN1 original, Cloner cloner) : base(original, cloner) { }
|
---|
55 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
56 | return new SchafferN1(this, cloner);
|
---|
57 | }
|
---|
58 |
|
---|
59 | public SchafferN1() : base() { }
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | public override double[] Evaluate(RealVector r, int objectives) {
|
---|
66 | if (objectives != 2) throw new ArgumentException("The Schaffer N1 problem must always have 2 objectives");
|
---|
67 | if (r.Length != 1) return null;
|
---|
68 | double x = r[0];
|
---|
69 |
|
---|
70 | //objective1
|
---|
71 | double f0 = x * x;
|
---|
72 |
|
---|
73 | //objective0
|
---|
74 | double f1 = x - 2;
|
---|
75 | f1 *= f1;
|
---|
76 |
|
---|
77 | return new double[] { f0, f1 };
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|