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

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

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

File size: 2.4 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 MoveEvaluatorAdapter : SingleSuccessorOperator, ISingleObjectiveMoveEvaluator {
20
21    public IConstrainedValueParameter<ISingleObjectiveEvaluator> EvaluatorParameter {
22      get { return (IConstrainedValueParameter<ISingleObjectiveEvaluator>) Parameters["Evaluator"]; }
23    }
24
25    public ISingleObjectiveEvaluator Evaluator { get { return EvaluatorParameter.Value; } }
26
27    #region construction & cloning
28
29    [StorableConstructor]
30    public MoveEvaluatorAdapter(bool isDeserializing) : base(isDeserializing) {}
31
32    public MoveEvaluatorAdapter(MoveEvaluatorAdapter orig, Cloner cloner) : base(orig, cloner) { }
33
34    public MoveEvaluatorAdapter() {
35      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "the move quality"));
36      var evaluators = new ItemSet<ISingleObjectiveEvaluator>();
37      evaluators.Add(new AggregateEvaluator());
38      evaluators.Add(new MonolithicEvaluator());
39      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveEvaluator>("Evaluator", "The actual evaluator.", evaluators));
40      EvaluatorParameter.Value = EvaluatorParameter.ValidValues.FirstOrDefault(e => e.GetType() == typeof(MonolithicEvaluator));
41    }
42
43    public override IDeepCloneable Clone(Cloner cloner) { return new MoveEvaluatorAdapter(this, cloner); }
44
45    #endregion
46
47    public ILookupParameter<DoubleValue> QualityParameter { get { return Evaluator.QualityParameter; } }
48
49    public ILookupParameter<DoubleValue> MoveQualityParameter { get { return (ILookupParameter<DoubleValue>) Parameters["MoveQuality"]; } }
50
51    public override IOperation Apply() {
52      var evaluator = (ISingleObjectiveEvaluator)Evaluator.Clone();
53      evaluator.QualityParameter.ActualName = MoveQualityParameter.ActualName;
54      return new OperationCollection {
55        ExecutionContext.CreateChildOperation(evaluator),
56        base.Apply(),
57      };
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.