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.Operators.Mutation;
|
---|
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 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 | }
|
---|