Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Moves/MoveMakerAdapter.cs @ 13071

Last change on this file since 13071 was 13071, checked in by gkronber, 8 years ago

#2499: added license headers and removed unused usings

File size: 3.0 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 System.Linq;
23using HeuristicLab.BioBoost.Evaluators;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.PluginInfrastructure;
32
33namespace HeuristicLab.BioBoost.Operators.Moves {
34
35  [StorableClass]
36  public class MoveMakerAdapter : SingleSuccessorOperator, IMoveMaker {
37
38    public IConstrainedValueParameter<ISingleObjectiveEvaluator> EvaluatorParameter { get { return (IConstrainedValueParameter<ISingleObjectiveEvaluator>) Parameters["Evaluator"]; } }
39    public ISingleObjectiveEvaluator Evaluator { get { return EvaluatorParameter.Value; } }
40
41    #region construction & cloning
42    [StorableConstructor]
43    public MoveMakerAdapter(bool isDeserializing) : base(isDeserializing) { }
44
45    public MoveMakerAdapter(MoveMakerAdapter orig, Cloner cloner) : base(orig, cloner) { }
46
47    public MoveMakerAdapter() {
48      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "the move quality"));
49      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveEvaluator>("Evaluator", "The actual evaluator.",
50        new ItemSet<ISingleObjectiveEvaluator>(ApplicationManager.Manager.GetInstances<ISingleObjectiveEvaluator>())));
51      EvaluatorParameter.Value =
52        EvaluatorParameter.ValidValues.FirstOrDefault(e => e.GetType() == typeof (MonolithicEvaluator));
53    }
54
55    public override IDeepCloneable Clone(Cloner cloner) { return new MoveMakerAdapter(this, cloner); }
56    #endregion
57
58    public ILookupParameter<DoubleValue> QualityParameter { get { return Evaluator.QualityParameter; } }
59
60    public ILookupParameter<DoubleValue> MoveQualityParameter { get { return (ILookupParameter<DoubleValue>) Parameters["MoveQuality"]; } }
61
62    public override IOperation Apply() {
63      var parentScope = ExecutionContext.Scope.Parent;
64      foreach (var variable in ExecutionContext.Scope.Variables) {
65        parentScope.Variables.Remove(variable.Name);
66        parentScope.Variables.Add(new Variable(variable.Name, variable.Value));
67      }
68      return base.Apply();
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.