[3150] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 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;
|
---|
[4722] | 23 | using HeuristicLab.Common;
|
---|
[3150] | 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[3154] | 26 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3150] | 28 |
|
---|
[3170] | 29 | namespace HeuristicLab.Problems.TestFunctions {
|
---|
[3150] | 30 | /// <summary>
|
---|
[3315] | 31 | /// The Rosenbrock function features a flat valley in which the global optimum is located.
|
---|
| 32 | /// It is implemented as generalized Rosenbrock function as for example given in Shang, Y.-W. and Qiu, Y.-H. 2006. A Note on the Extended Rosenbrock Function. Evolutionary Computation 14, pp. 119-126, MIT Press.
|
---|
[3150] | 33 | /// </summary>
|
---|
[3315] | 34 | [Item("RosenbrockEvaluator", @"The Rosenbrock function features a flat valley in which the global optimum is located.
|
---|
[3318] | 35 | For 2 and 3 dimensions the single minimum of this function is 0 at (1,1,...,1), for 4 to 30 dimensions there is an additional local minimum close to (-1,1,...,1).
|
---|
[3315] | 36 | It is unknown how many local minima there are for dimensions greater than 30.
|
---|
[3318] | 37 | It is implemented as generalized Rosenbrock function for which the 2 dimensional function is a special case, as for example given in Shang, Y.-W. and Qiu, Y.-H. 2006. A Note on the Extended Rosenbrock Function. Evolutionary Computation 14, pp. 119-126, MIT Press.")]
|
---|
[3154] | 38 | [StorableClass]
|
---|
[3170] | 39 | public class RosenbrockEvaluator : SingleObjectiveTestFunctionProblemEvaluator {
|
---|
[9990] | 40 | public override string FunctionName { get { return "Rosenbrock"; } }
|
---|
[3154] | 41 | /// <summary>
|
---|
| 42 | /// Returns false as the Rosenbrock function is a minimization problem.
|
---|
| 43 | /// </summary>
|
---|
| 44 | public override bool Maximization {
|
---|
| 45 | get { return false; }
|
---|
[3150] | 46 | }
|
---|
[3154] | 47 | /// <summary>
|
---|
| 48 | /// Gets the optimum function value (0).
|
---|
| 49 | /// </summary>
|
---|
| 50 | public override double BestKnownQuality {
|
---|
| 51 | get { return 0; }
|
---|
| 52 | }
|
---|
| 53 | /// <summary>
|
---|
| 54 | /// Gets the lower and upper bound of the function.
|
---|
| 55 | /// </summary>
|
---|
| 56 | public override DoubleMatrix Bounds {
|
---|
| 57 | get { return new DoubleMatrix(new double[,] { { -2.048, 2.048 } }); }
|
---|
| 58 | }
|
---|
| 59 | /// <summary>
|
---|
| 60 | /// Gets the minimum problem size (2).
|
---|
| 61 | /// </summary>
|
---|
| 62 | public override int MinimumProblemSize {
|
---|
| 63 | get { return 2; }
|
---|
| 64 | }
|
---|
| 65 | /// <summary>
|
---|
| 66 | /// Gets the (theoretical) maximum problem size (2^31 - 1).
|
---|
| 67 | /// </summary>
|
---|
| 68 | public override int MaximumProblemSize {
|
---|
| 69 | get { return int.MaxValue; }
|
---|
| 70 | }
|
---|
[3150] | 71 |
|
---|
[4722] | 72 | [StorableConstructor]
|
---|
| 73 | protected RosenbrockEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 74 | protected RosenbrockEvaluator(RosenbrockEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 75 | public RosenbrockEvaluator() : base() { }
|
---|
| 76 |
|
---|
| 77 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 78 | return new RosenbrockEvaluator(this, cloner);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[3781] | 81 | public override RealVector GetBestKnownSolution(int dimension) {
|
---|
| 82 | if (dimension < 2) throw new ArgumentException(Name + ": This function is not defined for 1 dimension.");
|
---|
| 83 | RealVector result = new RealVector(dimension);
|
---|
| 84 | for (int i = 0; i < dimension; i++) result[i] = 1;
|
---|
| 85 | return result;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[3150] | 88 | /// <summary>
|
---|
| 89 | /// Evaluates the test function for a specific <paramref name="point"/>.
|
---|
| 90 | /// </summary>
|
---|
| 91 | /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
|
---|
| 92 | /// <returns>The result value of the Rosenbrock function at the given point.</returns>
|
---|
[3154] | 93 | public static double Apply(RealVector point) {
|
---|
[3150] | 94 | double result = 0;
|
---|
| 95 | for (int i = 0; i < point.Length - 1; i++) {
|
---|
[3315] | 96 | result += 100 * (point[i] * point[i] - point[i + 1]) * (point[i] * point[i] - point[i + 1]);
|
---|
| 97 | result += (point[i] - 1) * (point[i] - 1);
|
---|
[3150] | 98 | }
|
---|
| 99 | return result;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /// <summary>
|
---|
| 103 | /// Evaluates the test function for a specific <paramref name="point"/>.
|
---|
| 104 | /// </summary>
|
---|
| 105 | /// <remarks>Calls <see cref="Apply"/>.</remarks>
|
---|
| 106 | /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
|
---|
| 107 | /// <returns>The result value of the Rosenbrock function at the given point.</returns>
|
---|
[9407] | 108 | public override double Evaluate(RealVector point) {
|
---|
[3150] | 109 | return Apply(point);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | }
|
---|