[3170] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3170] | 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 |
|
---|
[4722] | 22 | using HeuristicLab.Common;
|
---|
[3170] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.TestFunctions {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// Base class for a test function evaluator.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [Item("Evaluator", "Base calls for single objective test function evaluators.")]
|
---|
| 35 | [StorableClass]
|
---|
| 36 | public abstract class SingleObjectiveTestFunctionProblemEvaluator : SingleSuccessorOperator, ISingleObjectiveTestFunctionProblemEvaluator {
|
---|
| 37 | /// <summary>
|
---|
[9990] | 38 | /// The name of the function
|
---|
| 39 | /// </summary>
|
---|
| 40 | public abstract string FunctionName { get; }
|
---|
| 41 | /// <summary>
|
---|
[3520] | 42 | /// These operators should not change their name through the GUI
|
---|
| 43 | /// </summary>
|
---|
| 44 | public override bool CanChangeName {
|
---|
| 45 | get { return false; }
|
---|
| 46 | }
|
---|
| 47 | /// <summary>
|
---|
[3170] | 48 | /// Returns whether the actual function constitutes a maximization or minimization problem.
|
---|
| 49 | /// </summary>
|
---|
| 50 | public abstract bool Maximization { get; }
|
---|
| 51 | /// <summary>
|
---|
| 52 | /// Gets the lower and upper bound of the function.
|
---|
| 53 | /// </summary>
|
---|
| 54 | public abstract DoubleMatrix Bounds { get; }
|
---|
| 55 | /// <summary>
|
---|
| 56 | /// Gets the optimum function value.
|
---|
| 57 | /// </summary>
|
---|
| 58 | public abstract double BestKnownQuality { get; }
|
---|
| 59 | /// <summary>
|
---|
| 60 | /// Gets the minimum problem size.
|
---|
| 61 | /// </summary>
|
---|
| 62 | public abstract int MinimumProblemSize { get; }
|
---|
| 63 | /// <summary>
|
---|
| 64 | /// Gets the maximum problem size.
|
---|
| 65 | /// </summary>
|
---|
| 66 | public abstract int MaximumProblemSize { get; }
|
---|
| 67 |
|
---|
| 68 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 69 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 70 | }
|
---|
| 71 | public ILookupParameter<RealVector> PointParameter {
|
---|
| 72 | get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
|
---|
| 73 | }
|
---|
[4722] | 74 |
|
---|
| 75 | [StorableConstructor]
|
---|
| 76 | protected SingleObjectiveTestFunctionProblemEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 77 | protected SingleObjectiveTestFunctionProblemEvaluator(SingleObjectiveTestFunctionProblemEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
[3170] | 78 | /// <summary>
|
---|
| 79 | /// Initializes a new instance of <see cref="SingleObjectiveTestFunctionEvaluator"/> with two parameters
|
---|
| 80 | /// (<c>Quality</c> and <c>Point</c>).
|
---|
| 81 | /// </summary>
|
---|
[4722] | 82 | public SingleObjectiveTestFunctionProblemEvaluator()
|
---|
| 83 | : base() {
|
---|
[3170] | 84 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Result of the evaluation of a solution."));
|
---|
| 85 | Parameters.Add(new LookupParameter<RealVector>("Point", "The point at which the function should be evaluated."));
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public override IOperation Apply() {
|
---|
| 89 | RealVector point = PointParameter.ActualValue;
|
---|
[9407] | 90 | double quality = Evaluate(point);
|
---|
[3170] | 91 | QualityParameter.ActualValue = new DoubleValue(quality);
|
---|
| 92 | return base.Apply();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[3665] | 95 | public virtual double Evaluate2D(double x, double y) {
|
---|
[9407] | 96 | return Evaluate(new RealVector(new double[] { x, y }));
|
---|
[3665] | 97 | }
|
---|
| 98 |
|
---|
[3170] | 99 | /// <summary>
|
---|
| 100 | /// Evaluates the test function for a specific <paramref name="point"/>.
|
---|
| 101 | /// </summary>
|
---|
| 102 | /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
|
---|
| 103 | /// <returns>The result value of the function at the given point.</returns>
|
---|
[9407] | 104 | public abstract double Evaluate(RealVector point);
|
---|
[9345] | 105 |
|
---|
| 106 | /// <summary>
|
---|
| 107 | /// Gets the best known solution for this function.
|
---|
| 108 | /// </summary>
|
---|
| 109 | public abstract RealVector GetBestKnownSolution(int dimension);
|
---|
[3170] | 110 | }
|
---|
| 111 | }
|
---|