Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Moves/MoveGeneratorAdapter.cs @ 16575

Last change on this file since 16575 was 16575, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.BioBoost addon to compile with new HL.Persistence

File size: 3.6 KB
Line 
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
22using System.Linq;
23using HeuristicLab.BioBoost.Operators.Mutation;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.PluginInfrastructure;
32using HEAL.Attic;
33
34namespace 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}
Note: See TracBrowser for help on using the repository browser.