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 | /// 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 |
|
---|
71 | [StorableConstructor]
|
---|
72 | protected SingleObjectiveTestFunctionProblemEvaluator(bool deserializing) : base(deserializing) { }
|
---|
73 | protected SingleObjectiveTestFunctionProblemEvaluator(SingleObjectiveTestFunctionProblemEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
74 | /// <summary>
|
---|
75 | /// Initializes a new instance of <see cref="SingleObjectiveTestFunctionEvaluator"/> with two parameters
|
---|
76 | /// (<c>Quality</c> and <c>Point</c>).
|
---|
77 | /// </summary>
|
---|
78 | public SingleObjectiveTestFunctionProblemEvaluator()
|
---|
79 | : base() {
|
---|
80 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Result of the evaluation of a solution."));
|
---|
81 | Parameters.Add(new LookupParameter<RealVector>("Point", "The point at which the function should be evaluated."));
|
---|
82 | }
|
---|
83 |
|
---|
84 | public override IOperation Apply(IExecutionContext context) {
|
---|
85 | RealVector point = PointParameter.ActualValue;
|
---|
86 | double quality = EvaluateFunction(point);
|
---|
87 | QualityParameter.ActualValue = new DoubleValue(quality);
|
---|
88 | return base.Apply(context);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public virtual double Evaluate2D(double x, double y) {
|
---|
92 | return EvaluateFunction(new RealVector(new double[] { x, y }));
|
---|
93 | }
|
---|
94 | /// <summary>
|
---|
95 | /// Gets the best known solution for this function.
|
---|
96 | /// </summary>
|
---|
97 | public abstract RealVector GetBestKnownSolution(int dimension);
|
---|
98 |
|
---|
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>
|
---|
104 | protected abstract double EvaluateFunction(RealVector point);
|
---|
105 | }
|
---|
106 | }
|
---|