1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
11 | using HeuristicLab.Problems.MultiObjectiveTestFunction;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Problems.TestFunctions {
|
---|
14 | [Item("SchafferN2", "from // https://en.wikipedia.org/wiki/Test_functions_for_optimization [30.11.2015]")]
|
---|
15 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 210)]
|
---|
16 | [StorableClass]
|
---|
17 | public class SchafferN2 : MultiObjectiveTestFunction {
|
---|
18 |
|
---|
19 | public override DoubleMatrix Bounds {
|
---|
20 | get {
|
---|
21 | return new DoubleMatrix(new double[,] { { -5, 10 } });
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override bool[] Maximization {
|
---|
26 | get {
|
---|
27 | return new bool[] { false, false };
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | public override int MaximumProblemSize {
|
---|
32 | get {
|
---|
33 | return 1;
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public override int MaximumSolutionSize {
|
---|
38 | get {
|
---|
39 | return 2;
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override int MinimumProblemSize {
|
---|
44 | get {
|
---|
45 | return 1;
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public override int MinimumSolutionSize {
|
---|
50 | get {
|
---|
51 | return 2;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | [StorableConstructor]
|
---|
56 | protected SchafferN2(bool deserializing) : base(deserializing) { }
|
---|
57 | protected SchafferN2(SchafferN2 original, Cloner cloner) : base(original, cloner) { }
|
---|
58 | public SchafferN2() : base() { }
|
---|
59 |
|
---|
60 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
61 | return new SchafferN2(this, cloner);
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | public override double[] Evaluate(RealVector r) {
|
---|
67 | double x = r[0];
|
---|
68 |
|
---|
69 | //objective1
|
---|
70 | double f0;
|
---|
71 | if (x <= 11) f0 = -x;
|
---|
72 | else if (x <= 3) f0 = x - 2;
|
---|
73 | else if (x <= 4) f0 = 4 - x;
|
---|
74 | else f0 = x - 4;
|
---|
75 |
|
---|
76 | //objective0
|
---|
77 | double f1 = x - 5;
|
---|
78 | f1 *= f1;
|
---|
79 |
|
---|
80 | return new double[] { f0, f1 };
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|