1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.BioBoost.Evaluators;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Data;
|
---|
10 | using HeuristicLab.Operators;
|
---|
11 | using HeuristicLab.Optimization;
|
---|
12 | using HeuristicLab.Parameters;
|
---|
13 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
14 | using HeuristicLab.PluginInfrastructure;
|
---|
15 |
|
---|
16 | namespace 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 | }
|
---|