[3150] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[3154] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3150] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
[3154] | 25 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
[4068] | 26 | using HeuristicLab.Parameters;
|
---|
[3154] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3150] | 28 |
|
---|
[3170] | 29 | namespace HeuristicLab.Problems.TestFunctions {
|
---|
[3150] | 30 | /// <summary>
|
---|
[3315] | 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.
|
---|
[3150] | 33 | /// </summary>
|
---|
[3315] | 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.")]
|
---|
[3154] | 35 | [StorableClass]
|
---|
[3170] | 36 | public class SphereEvaluator : SingleObjectiveTestFunctionProblemEvaluator {
|
---|
[3154] | 37 | /// <summary>
|
---|
[3315] | 38 | /// Returns false as the Sphere function is a minimization problem.
|
---|
[3154] | 39 | /// </summary>
|
---|
| 40 | public override bool Maximization {
|
---|
| 41 | get { return false; }
|
---|
[3150] | 42 | }
|
---|
[3154] | 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 | }
|
---|
[3781] | 67 |
|
---|
| 68 | public override RealVector GetBestKnownSolution(int dimension) {
|
---|
| 69 | return new RealVector(dimension);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[3315] | 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 | }
|
---|
[3150] | 98 |
|
---|
| 99 | /// <summary>
|
---|
[3315] | 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>
|
---|
[3150] | 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>
|
---|
[3315] | 112 | public static double Apply(RealVector point, double c, double alpha) {
|
---|
[3150] | 113 | double result = 0;
|
---|
| 114 | for (int i = 0; i < point.Length; i++)
|
---|
| 115 | result += point[i] * point[i];
|
---|
[3315] | 116 | if (alpha != 2) result = Math.Pow(Math.Sqrt(result), alpha);
|
---|
| 117 | return c * result;
|
---|
[3150] | 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>
|
---|
[3154] | 126 | protected override double EvaluateFunction(RealVector point) {
|
---|
[3315] | 127 | return Apply(point, C.Value, Alpha.Value);
|
---|
[3150] | 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|