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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
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>
|
---|
38 | /// Returns whether the actual function constitutes a maximization or minimization problem.
|
---|
39 | /// </summary>
|
---|
40 | public abstract bool Maximization { get; }
|
---|
41 | /// <summary>
|
---|
42 | /// Gets the lower and upper bound of the function.
|
---|
43 | /// </summary>
|
---|
44 | public abstract DoubleMatrix Bounds { get; }
|
---|
45 | /// <summary>
|
---|
46 | /// Gets the optimum function value.
|
---|
47 | /// </summary>
|
---|
48 | public abstract double BestKnownQuality { get; }
|
---|
49 | /// <summary>
|
---|
50 | /// Gets the minimum problem size.
|
---|
51 | /// </summary>
|
---|
52 | public abstract int MinimumProblemSize { get; }
|
---|
53 | /// <summary>
|
---|
54 | /// Gets the maximum problem size.
|
---|
55 | /// </summary>
|
---|
56 | public abstract int MaximumProblemSize { get; }
|
---|
57 |
|
---|
58 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
59 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
60 | }
|
---|
61 | public ILookupParameter<RealVector> PointParameter {
|
---|
62 | get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
|
---|
63 | }
|
---|
64 | /// <summary>
|
---|
65 | /// Initializes a new instance of <see cref="SingleObjectiveTestFunctionEvaluator"/> with two parameters
|
---|
66 | /// (<c>Quality</c> and <c>Point</c>).
|
---|
67 | /// </summary>
|
---|
68 | public SingleObjectiveTestFunctionProblemEvaluator() {
|
---|
69 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Result of the evaluation of a solution."));
|
---|
70 | Parameters.Add(new LookupParameter<RealVector>("Point", "The point at which the function should be evaluated."));
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override IOperation Apply() {
|
---|
74 | RealVector point = PointParameter.ActualValue;
|
---|
75 | double quality = EvaluateFunction(point);
|
---|
76 | QualityParameter.ActualValue = new DoubleValue(quality);
|
---|
77 | return base.Apply();
|
---|
78 | }
|
---|
79 |
|
---|
80 | /// <summary>
|
---|
81 | /// Evaluates the test function for a specific <paramref name="point"/>.
|
---|
82 | /// </summary>
|
---|
83 | /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
|
---|
84 | /// <returns>The result value of the function at the given point.</returns>
|
---|
85 | protected abstract double EvaluateFunction(RealVector point);
|
---|
86 | }
|
---|
87 | }
|
---|