1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.BioBoost.Operators.Mutation;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.PluginInfrastructure;
|
---|
32 | using HEAL.Attic;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.BioBoost.Operators.Moves {
|
---|
35 |
|
---|
36 | [StorableType("01CF5EC3-F344-4A73-9BCD-7CE329392552")]
|
---|
37 | public class MoveGeneratorAdapter : SingleSuccessorOperator, IMoveGenerator {
|
---|
38 |
|
---|
39 | public IConstrainedValueParameter<IManipulator> ManipulatorParameter { get { return (IConstrainedValueParameter<IManipulator>) Parameters["Manipulator"]; } }
|
---|
40 | public IManipulator Manipulator { get { return ManipulatorParameter.Value; } }
|
---|
41 |
|
---|
42 | public IValueLookupParameter<IntValue> SampleSizeParameter { get { return (IValueLookupParameter<IntValue>) Parameters["SampleSize"]; } }
|
---|
43 | public int SampleSize { get { return SampleSizeParameter.ActualValue.Value; } }
|
---|
44 |
|
---|
45 | #region construction & cloning
|
---|
46 | [StorableConstructor]
|
---|
47 | public MoveGeneratorAdapter(StorableConstructorFlag _) : base(_) { }
|
---|
48 |
|
---|
49 | public MoveGeneratorAdapter(MoveGeneratorAdapter orig, Cloner cloner) : base(orig, cloner) { }
|
---|
50 |
|
---|
51 | public MoveGeneratorAdapter() {
|
---|
52 | Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
|
---|
53 | Parameters.Add(new LookupParameter<IntValue>("Generations", "rename value to iterations", "Iterations"));
|
---|
54 | Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "rename value to maximum iterations", "MaximumIterations"));
|
---|
55 | Parameters.Add(new ConstrainedValueParameter<IManipulator>("Manipulator", "The actual maniuplator that should be wrapped.",
|
---|
56 | new ItemSet<IManipulator>(ApplicationManager.Manager.GetInstances<IManipulator>())));
|
---|
57 | ManipulatorParameter.Value =
|
---|
58 | ManipulatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == typeof (MultiMutator));
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) { return new MoveGeneratorAdapter(this, cloner); }
|
---|
62 | #endregion
|
---|
63 |
|
---|
64 | public override IOperation Apply() {
|
---|
65 | var successors = new OperationCollection();
|
---|
66 | for (int i = 0; i < SampleSize; i++) {
|
---|
67 | var subscope = new Scope(i.ToString());
|
---|
68 | foreach (var variable in ExecutionContext.Scope.Variables) {
|
---|
69 | subscope.Variables.Add(new Variable(variable.Name, (IItem) variable.Value.Clone()));
|
---|
70 | }
|
---|
71 | ExecutionContext.Scope.SubScopes.Add(subscope);
|
---|
72 | successors.Add(ExecutionContext.CreateChildOperation((IOperator) Manipulator.Clone(), subscope));
|
---|
73 | }
|
---|
74 | successors.Add(base.Apply());
|
---|
75 | return successors;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|