source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Moves/MoveGeneratorAdapter.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.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.BioBoost.Operators.Mutation;
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 MoveGeneratorAdapter : SingleSuccessorOperator, IMoveGenerator {
20
21    public IConstrainedValueParameter<IManipulator> ManipulatorParameter { get { return (IConstrainedValueParameter<IManipulator>) Parameters["Manipulator"]; } }
22    public IManipulator Manipulator { get { return ManipulatorParameter.Value; } }
23
24    public IValueLookupParameter<IntValue> SampleSizeParameter { get { return (IValueLookupParameter<IntValue>) Parameters["SampleSize"]; } }
25    public int SampleSize { get { return SampleSizeParameter.ActualValue.Value; } }
26
27    #region construction & cloning
28    [StorableConstructor]
29    public MoveGeneratorAdapter(bool isDeserializing) : base(isDeserializing) { }
30
31    public MoveGeneratorAdapter(MoveGeneratorAdapter orig, Cloner cloner) : base(orig, cloner) { }
32
33    public MoveGeneratorAdapter() {
34      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
35      Parameters.Add(new LookupParameter<IntValue>("Generations", "rename value to iterations", "Iterations"));
36      Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "rename value to maximum iterations", "MaximumIterations"));
37      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Manipulator", "The actual maniuplator that should be wrapped.",
38        new ItemSet<IManipulator>(ApplicationManager.Manager.GetInstances<IManipulator>())));
39      ManipulatorParameter.Value =
40        ManipulatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == typeof (MultiMutator));
41    }
42
43    public override IDeepCloneable Clone(Cloner cloner) { return new MoveGeneratorAdapter(this, cloner); }
44    #endregion
45
46    public override IOperation Apply() {
47      var successors = new OperationCollection();
48      for (int i = 0; i < SampleSize; i++) {
49        var subscope = new Scope(i.ToString());
50        foreach (var variable in ExecutionContext.Scope.Variables) {
51          subscope.Variables.Add(new Variable(variable.Name, (IItem) variable.Value.Clone()));
52        }
53        ExecutionContext.Scope.SubScopes.Add(subscope);
54        successors.Add(ExecutionContext.CreateChildOperation((IOperator) Manipulator.Clone(), subscope));
55      }
56      successors.Add(base.Apply());
57      return successors;
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.