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

Last change on this file since 13069 was 13069, checked in by gkronber, 5 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.BioBoost.Evaluators;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10using HeuristicLab.Operators;
11using HeuristicLab.Optimization;
12using HeuristicLab.Parameters;
13using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
14using HeuristicLab.PluginInfrastructure;
15
16namespace HeuristicLab.BioBoost.Operators.Moves {
17
18  [StorableClass]
19  public class MoveMakerAdapter : SingleSuccessorOperator, IMoveMaker {
20
21    public IConstrainedValueParameter<ISingleObjectiveEvaluator> EvaluatorParameter { get { return (IConstrainedValueParameter<ISingleObjectiveEvaluator>) Parameters["Evaluator"]; } }
22    public ISingleObjectiveEvaluator Evaluator { get { return EvaluatorParameter.Value; } }
23
24    #region construction & cloning
25    [StorableConstructor]
26    public MoveMakerAdapter(bool isDeserializing) : base(isDeserializing) { }
27
28    public MoveMakerAdapter(MoveMakerAdapter orig, Cloner cloner) : base(orig, cloner) { }
29
30    public MoveMakerAdapter() {
31      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "the move quality"));
32      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveEvaluator>("Evaluator", "The actual evaluator.",
33        new ItemSet<ISingleObjectiveEvaluator>(ApplicationManager.Manager.GetInstances<ISingleObjectiveEvaluator>())));
34      EvaluatorParameter.Value =
35        EvaluatorParameter.ValidValues.FirstOrDefault(e => e.GetType() == typeof (MonolithicEvaluator));
36    }
37
38    public override IDeepCloneable Clone(Cloner cloner) { return new MoveMakerAdapter(this, cloner); }
39    #endregion
40
41    public ILookupParameter<DoubleValue> QualityParameter { get { return Evaluator.QualityParameter; } }
42
43    public ILookupParameter<DoubleValue> MoveQualityParameter { get { return (ILookupParameter<DoubleValue>) Parameters["MoveQuality"]; } }
44
45    public override IOperation Apply() {
46      var parentScope = ExecutionContext.Scope.Parent;
47      foreach (var variable in ExecutionContext.Scope.Variables) {
48        parentScope.Variables.Remove(variable.Name);
49        parentScope.Variables.Add(new Variable(variable.Name, variable.Value));
50      }
51      return base.Apply();
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.