Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13403 was 13403, checked in by abeham, 8 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
RevLine 
[3187]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3187]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
[4722]22using HeuristicLab.Common;
[3187]23using HeuristicLab.Core;
24using HeuristicLab.Data;
[4068]25using HeuristicLab.Encodings.RealVectorEncoding;
[3187]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]
[13403]33  public class AdditiveMoveEvaluator : SingleSuccessorOperator, ISingleObjectiveTestFunctionAdditiveMoveEvaluator {
[3520]34
35    public override bool CanChangeName {
36      get { return false; }
37    }
38
[3187]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    }
[13403]51    public ILookupParameter<ISingleObjectiveTestFunction> TestFunctionParameter {
52      get { return (ILookupParameter<ISingleObjectiveTestFunction>)Parameters["TestFunction"]; }
53    }
[3187]54
[4722]55    [StorableConstructor]
56    protected AdditiveMoveEvaluator(bool deserializing) : base(deserializing) { }
57    protected AdditiveMoveEvaluator(AdditiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
[13403]58    public AdditiveMoveEvaluator()
[3187]59      : base() {
[3685]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."));
[3187]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."));
[13403]64      Parameters.Add(new LookupParameter<ISingleObjectiveTestFunction>("TestFunction", "The test function that is used."));
[3187]65    }
66
[13403]67    public override IDeepCloneable Clone(Cloner cloner) {
68      return new AdditiveMoveEvaluator(this, cloner);
69    }
70
[3187]71    public override IOperation Apply() {
[13403]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;
[3187]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.