Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/MoveEvaluators/AdditiveMoveEvaluator.cs @ 14000

Last change on this file since 14000 was 13403, checked in by abeham, 9 years ago

#2521:

  • Adapted single-objective test function problem to new problem infrastructure
  • Added additional interfaces to RealVectorEncoding
  • Fixed IParticleUpdater interface (must implement IStochasticOperator if it contains a Random parameter)
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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  [Item("AdditiveMoveEvaluator", "Base class for evaluating an additive move.")]
32  [StorableClass]
33  public class AdditiveMoveEvaluator : SingleSuccessorOperator, ISingleObjectiveTestFunctionAdditiveMoveEvaluator {
34
35    public override bool CanChangeName {
36      get { return false; }
37    }
38
39    public ILookupParameter<DoubleValue> QualityParameter {
40      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
41    }
42    public ILookupParameter<DoubleValue> MoveQualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
44    }
45    public ILookupParameter<RealVector> RealVectorParameter {
46      get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
47    }
48    public ILookupParameter<AdditiveMove> AdditiveMoveParameter {
49      get { return (ILookupParameter<AdditiveMove>)Parameters["AdditiveMove"]; }
50    }
51    public ILookupParameter<ISingleObjectiveTestFunction> TestFunctionParameter {
52      get { return (ILookupParameter<ISingleObjectiveTestFunction>)Parameters["TestFunction"]; }
53    }
54
55    [StorableConstructor]
56    protected AdditiveMoveEvaluator(bool deserializing) : base(deserializing) { }
57    protected AdditiveMoveEvaluator(AdditiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
58    public AdditiveMoveEvaluator()
59      : base() {
60      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a test function solution."));
61      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a test function solution."));
62      Parameters.Add(new LookupParameter<RealVector>("Point", "The point to evaluate the move on."));
63      Parameters.Add(new LookupParameter<AdditiveMove>("AdditiveMove", "The move to evaluate."));
64      Parameters.Add(new LookupParameter<ISingleObjectiveTestFunction>("TestFunction", "The test function that is used."));
65    }
66
67    public override IDeepCloneable Clone(Cloner cloner) {
68      return new AdditiveMoveEvaluator(this, cloner);
69    }
70
71    public override IOperation Apply() {
72      var function = TestFunctionParameter.ActualValue;
73      var move = AdditiveMoveParameter.ActualValue;
74      var vector = RealVectorParameter.ActualValue;
75      var clone = (RealVector)vector.Clone();
76
77      AdditiveMoveMaker.Apply(clone, move);
78      var mq = function.Evaluate(clone);
79
80      var moveQuality = MoveQualityParameter.ActualValue;
81      if (moveQuality == null) {
82        MoveQualityParameter.ActualValue = new DoubleValue(mq);
83      } else moveQuality.Value = mq;
84      return base.Apply();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.