Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SphereEvaluator.cs @ 4695

Last change on this file since 4695 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 5.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
22using System;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.TestFunctions {
30  /// <summary>
31  /// The sphere function is a unimodal function that has its optimum at the origin.
32  /// It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.
33  /// </summary>
34  [Item("SphereEvaluator", "Evaluates the Sphere function y = C * ||X||^Alpha on a given point. The optimum of this function is 0 at the origin. It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.")]
35  [StorableClass]
36  public class SphereEvaluator : SingleObjectiveTestFunctionProblemEvaluator {
37    /// <summary>
38    /// Returns false as the Sphere function is a minimization problem.
39    /// </summary>
40    public override bool Maximization {
41      get { return false; }
42    }
43    /// <summary>
44    /// Gets the optimum function value (0).
45    /// </summary>
46    public override double BestKnownQuality {
47      get { return 0; }
48    }
49    /// <summary>
50    /// Gets the lower and upper bound of the function.
51    /// </summary>
52    public override DoubleMatrix Bounds {
53      get { return new DoubleMatrix(new double[,] { { -5.12, 5.12 } }); }
54    }
55    /// <summary>
56    /// Gets the minimum problem size (1).
57    /// </summary>
58    public override int MinimumProblemSize {
59      get { return 1; }
60    }
61    /// <summary>
62    /// Gets the (theoretical) maximum problem size (2^31 - 1).
63    /// </summary>
64    public override int MaximumProblemSize {
65      get { return int.MaxValue; }
66    }
67
68    public override RealVector GetBestKnownSolution(int dimension) {
69      return new RealVector(dimension);
70    }
71
72    /// <summary>
73    /// The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.
74    /// </summary>
75    public ValueParameter<DoubleValue> CParameter {
76      get { return (ValueParameter<DoubleValue>)Parameters["C"]; }
77    }
78    /// <summary>
79    /// The parameter Alpha modifies the steepness of the objective function y = C * ||X||^Alpha. Default is Alpha = 2.
80    /// </summary>
81    public ValueParameter<DoubleValue> AlphaParameter {
82      get { return (ValueParameter<DoubleValue>)Parameters["Alpha"]; }
83    }
84    /// <summary>
85    /// The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.
86    /// </summary>
87    public DoubleValue C {
88      get { return CParameter.Value; }
89      set { if (value != null) CParameter.Value = value; }
90    }
91    /// <summary>
92    /// The parameter Alpha modifies the steepness of the objective function y = C * ||X||^Alpha. Default is Alpha = 2.
93    /// </summary>
94    public DoubleValue Alpha {
95      get { return AlphaParameter.Value; }
96      set { if (value != null) AlphaParameter.Value = value; }
97    }
98
99    /// <summary>
100    /// Initializes a new instance of the SphereEvaluator with two parameters (<c>C</c> and <c>Alpha</c>).
101    /// </summary>
102    public SphereEvaluator()
103      : base() {
104      Parameters.Add(new ValueParameter<DoubleValue>("C", "The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.", new DoubleValue(1)));
105      Parameters.Add(new ValueParameter<DoubleValue>("Alpha", "The parameter Alpha modifies the steepness of the objective function y = C * ||X||^Alpha. Default is Alpha = 2.", new DoubleValue(2)));
106    }
107    /// <summary>
108    /// Evaluates the test function for a specific <paramref name="point"/>.
109    /// </summary>
110    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
111    /// <returns>The result value of the Sphere function at the given point.</returns>
112    public static double Apply(RealVector point, double c, double alpha) {
113      double result = 0;
114      for (int i = 0; i < point.Length; i++)
115        result += point[i] * point[i];
116      if (alpha != 2) result = Math.Pow(Math.Sqrt(result), alpha);
117      return c * result;
118    }
119
120    /// <summary>
121    /// Evaluates the test function for a specific <paramref name="point"/>.
122    /// </summary>
123    /// <remarks>Calls <see cref="Apply"/>.</remarks>
124    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
125    /// <returns>The result value of the Sphere function at the given point.</returns>
126    protected override double EvaluateFunction(RealVector point) {
127      return Apply(point, C.Value, Alpha.Value);
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.