Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/26/15 09:56:33 (8 years ago)
Author:
abeham
Message:

#2521: Implemented SchafferF6 test function

Location:
branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/Functions/SchafferF6.cs

    r13403 r13405  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.RealVectorEncoding;
    27 using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    3029namespace HeuristicLab.Problems.TestFunctions {
    3130  /// <summary>
    32   /// The generalized Rastrigin function y = Sum((x_i)^2 + A * (1 - Cos(2pi*x_i))) is a highly multimodal function that has its optimal value 0 at the origin.
    33   /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.
     31  /// The generalized Rastrigin function y = 0.5 + (Sin^2(Sqrt(x^2 + y^2)) - 0.5) / (1 + 0.001 * (x^2 + y^2))^2 is a multimodal function that has its optimal value 0 at the origin.
     32
    3433  /// </summary
    35   [Item("Rastrigin", "Evaluates the generalized Rastrigin function y = Sum((x_i)^2 + A * (1 - Cos(2pi*x_i))) on a given point. The optimum of this function is 0 at the origin. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]
     34  [Item("SchafferF6", "Evaluates the Schaffer F6 function y = 0.5 + (Sin^2(Sqrt(x^2 + y^2)) - 0.5) / (1 + 0.001 * (x^2 + y^2))^2 on a given point. The optimum of this function is 0 at the origin. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg.")]
    3635  [StorableClass]
    37   public class Rastrigin : SingleObjectiveTestFunction {
     36  public class SchafferF6 : SingleObjectiveTestFunction {
    3837    /// <summary>
    3938    /// Returns false as the Rastrigin function is a minimization problem.
     
    5251    /// </summary>
    5352    public override DoubleMatrix Bounds {
    54       get { return new DoubleMatrix(new double[,] { { -5.12, 5.12 } }); }
     53      get { return new DoubleMatrix(new double[,] { { -100, 100 } }); }
    5554    }
    5655    /// <summary>
    57     /// Gets the minimum problem size (1).
     56    /// Gets the minimum problem size (2).
    5857    /// </summary>
    5958    public override int MinimumProblemSize {
    60       get { return 1; }
     59      get { return 2; }
    6160    }
    6261    /// <summary>
    63     /// Gets the (theoretical) maximum problem size (2^31 - 1).
     62    /// Gets the maximum problem size (2).
    6463    /// </summary>
    6564    public override int MaximumProblemSize {
    66       get { return int.MaxValue; }
    67     }
    68     /// <summary>
    69     /// The parameter A is a parameter of the objective function y = Sum((x_i)^2 + A * (1 - Cos(2pi*x_i))). Default is A = 10.
    70     /// </summary>
    71     public ValueParameter<DoubleValue> AParameter {
    72       get { return (ValueParameter<DoubleValue>)Parameters["A"]; }
    73     }
    74     /// <summary>
    75     /// The parameter A is a parameter of the objective function y = Sum((x_i)^2 + A * (1 - Cos(2pi*x_i))). Default is A = 10.
    76     /// </summary>
    77     public DoubleValue A {
    78       get { return AParameter.Value; }
    79       set { if (value != null) AParameter.Value = value; }
     65      get { return 2; }
    8066    }
    8167
     
    8571
    8672    [StorableConstructor]
    87     protected Rastrigin(bool deserializing) : base(deserializing) { }
    88     protected Rastrigin(Rastrigin original, Cloner cloner) : base(original, cloner) { }
    89     /// <summary>
    90     /// Initializes a new instance of the RastriginEvaluator with one parameter (<c>A</c>).
    91     /// </summary>
    92     public Rastrigin()
    93       : base() {
    94       Parameters.Add(new ValueParameter<DoubleValue>("A", "The parameter A is a parameter of the objective function y = Sum((x_i)^2 + A * (1 - Cos(2pi*x_i))). Default is A = 10.", new DoubleValue(10)));
    95     }
     73    protected SchafferF6(bool deserializing) : base(deserializing) { }
     74    protected SchafferF6(SchafferF6 original, Cloner cloner) : base(original, cloner) { }
     75    public SchafferF6() : base() { }
    9676
    9777    public override IDeepCloneable Clone(Cloner cloner) {
    98       return new Rastrigin(this, cloner);
     78      return new SchafferF6(this, cloner);
    9979    }
    10080
     
    10484    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
    10585    /// <returns>The result value of the Rastrigin function at the given point.</returns>
    106     public static double Apply(RealVector point, double a) {
    107       double result = a * point.Length;
    108       for (int i = 0; i < point.Length; i++) {
    109         result += point[i] * point[i];
    110         result -= a * Math.Cos(2 * Math.PI * point[i]);
    111       }
    112       return (result);
     86    public static double Apply(RealVector point) {
     87      if (point.Length != 2) throw new ArgumentException("The SchafferF6 can only be evaluated for two dimenional vectors");
     88      var sumSquare = point[0] * point[0] + point[1] * point[1];
     89      var sin = Math.Sin(Math.Sqrt(sumSquare));
     90      var nom = sin * sin - 0.5;
     91      var denom = (1 + 0.001 * sumSquare) * (1 + 0.001 * sumSquare);
     92      return 0.5 + nom / denom;
    11393    }
    11494
     
    120100    /// <returns>The result value of the Rastrigin function at the given point.</returns>
    121101    public override double Evaluate(RealVector point) {
    122       return Apply(point, A.Value);
     102      return Apply(point);
    123103    }
    124104  }
  • branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/HeuristicLab.Problems.TestFunctions-3.3.csproj

    r13403 r13405  
    115115  <ItemGroup>
    116116    <Compile Include="Functions\Random.cs" />
     117    <Compile Include="Functions\SchafferF6.cs" />
    117118    <Compile Include="Improvers\SingleObjectiveTestFunctionImprovementOperator.cs" />
    118119    <Compile Include="Instances\SOTFData.cs" />
Note: See TracChangeset for help on using the changeset viewer.