source: trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SingleObjectiveTestFunctionProblemEvaluator.cs @ 3665

Last change on this file since 3665 was 3665, checked in by abeham, 12 years ago

#934

  • added visualization for test functions
File size: 3.9 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace 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>
38    /// These operators should not change their name through the GUI
39    /// </summary>
40    public override bool CanChangeName {
41      get { return false; }
42    }
43    /// <summary>
44    /// Returns whether the actual function constitutes a maximization or minimization problem.
45    /// </summary>
46    public abstract bool Maximization { get; }
47    /// <summary>
48    /// Gets the lower and upper bound of the function.
49    /// </summary>
50    public abstract DoubleMatrix Bounds { get; }
51    /// <summary>
52    /// Gets the optimum function value.
53    /// </summary>
54    public abstract double BestKnownQuality { get; }
55    /// <summary>
56    /// Gets the minimum problem size.
57    /// </summary>
58    public abstract int MinimumProblemSize { get; }
59    /// <summary>
60    /// Gets the maximum problem size.
61    /// </summary>
62    public abstract int MaximumProblemSize { get; }
63
64    public ILookupParameter<DoubleValue> QualityParameter {
65      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
66    }
67    public ILookupParameter<RealVector> PointParameter {
68      get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
69    }
70    /// <summary>
71    /// Initializes a new instance of <see cref="SingleObjectiveTestFunctionEvaluator"/> with two parameters
72    /// (<c>Quality</c> and <c>Point</c>).
73    /// </summary>
74    public SingleObjectiveTestFunctionProblemEvaluator() {
75      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Result of the evaluation of a solution."));
76      Parameters.Add(new LookupParameter<RealVector>("Point", "The point at which the function should be evaluated."));
77    }
78
79    public override IOperation Apply() {
80      RealVector point = PointParameter.ActualValue;
81      double quality = EvaluateFunction(point);
82      QualityParameter.ActualValue = new DoubleValue(quality);
83      return base.Apply();
84    }
85
86    public virtual double Evaluate2D(double x, double y) {
87      return EvaluateFunction(new RealVector(new double[] { x, y }));
88    }
89
90    /// <summary>
91    /// Evaluates the test function for a specific <paramref name="point"/>.
92    /// </summary>
93    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
94    /// <returns>The result value of the function at the given point.</returns>
95    protected abstract double EvaluateFunction(RealVector point);
96  }
97}
Note: See TracBrowser for help on using the repository browser.