#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.RealVectorEncoding; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.TestFunctions { /// /// Base class for a test function evaluator. /// [Item("Evaluator", "Base calls for single objective test function evaluators.")] [StorableClass] public abstract class SingleObjectiveTestFunctionProblemEvaluator : SingleSuccessorOperator, ISingleObjectiveTestFunctionProblemEvaluator { /// /// These operators should not change their name through the GUI /// public override bool CanChangeName { get { return false; } } /// /// Returns whether the actual function constitutes a maximization or minimization problem. /// public abstract bool Maximization { get; } /// /// Gets the lower and upper bound of the function. /// public abstract DoubleMatrix Bounds { get; } /// /// Gets the optimum function value. /// public abstract double BestKnownQuality { get; } /// /// Gets the minimum problem size. /// public abstract int MinimumProblemSize { get; } /// /// Gets the maximum problem size. /// public abstract int MaximumProblemSize { get; } public ILookupParameter QualityParameter { get { return (ILookupParameter)Parameters["Quality"]; } } public ILookupParameter PointParameter { get { return (ILookupParameter)Parameters["Point"]; } } [StorableConstructor] protected SingleObjectiveTestFunctionProblemEvaluator(bool deserializing) : base(deserializing) { } protected SingleObjectiveTestFunctionProblemEvaluator(SingleObjectiveTestFunctionProblemEvaluator original, Cloner cloner) : base(original, cloner) { } /// /// Initializes a new instance of with two parameters /// (Quality and Point). /// public SingleObjectiveTestFunctionProblemEvaluator() : base() { Parameters.Add(new LookupParameter("Quality", "Result of the evaluation of a solution.")); Parameters.Add(new LookupParameter("Point", "The point at which the function should be evaluated.")); } public override IOperation Apply() { RealVector point = PointParameter.ActualValue; double quality = EvaluateFunction(point); QualityParameter.ActualValue = new DoubleValue(quality); return base.Apply(); } public virtual double Evaluate2D(double x, double y) { return EvaluateFunction(new RealVector(new double[] { x, y })); } /// /// Gets the best known solution for this function. /// public abstract RealVector GetBestKnownSolution(int dimension); /// /// Evaluates the test function for a specific . /// /// N-dimensional point for which the test function should be evaluated. /// The result value of the function at the given point. protected abstract double EvaluateFunction(RealVector point); } }