Free cookie consent management tool by TermsFeed Policy Generator

# source:branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/Fonseca.cs@13421

Last change on this file since 13421 was 13421, checked in by bwerth, 8 years ago

#1087 implemented skeleton structure and first testfunctions(Fonesca, SchafferN1 & SchafferN2)

File size: 2.2 KB
Line
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8using HeuristicLab.Data;
9using HeuristicLab.Encodings.RealVectorEncoding;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.Problems.MultiObjectiveTestFunction;
12
13namespace HeuristicLab.Problems.TestFunctions {
14  [Item("Fonseca", "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 Fonseca : MultiObjectiveTestFunction {
18
19    public override DoubleMatrix Bounds {
20      get {
21        return new DoubleMatrix(new double[,] { { -4, 4 } });
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 int.MaxValue;
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 Fonseca(bool deserializing) : base(deserializing) { }
57    protected Fonseca(Fonseca original, Cloner cloner) : base(original, cloner) { }
58    public Fonseca() : base() { }
59
60    public override IDeepCloneable Clone(Cloner cloner) {
61      return new Fonseca(this, cloner);
62    }
63
64
65
66    public override double[] Evaluate(RealVector r) {
67      double f0 = 0.0, aux = 1.0 / Math.Sqrt(r.Length);
68
69      //objective1
70      for (int i = 0; i < r.Length; i++) {
71        double d = r[i] - aux;
72        f0 += d * d;
73      }
74      f0 = 1 - Math.Exp(-f0);
75
76      //objective2
77      double f1 = 0.0;
78      for (int i = 0; i < r.Length; i++) {
79        double d = r[i] + aux;
80        f1 += d * d;
81      }
82      f1 = 1 - Math.Exp(-f1);
83
84      double[] res = { f0, f1 };
85      return res;
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.