source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Mutation/MultiIntegerVectorMutator.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: 3.4 KB
Line 
1using HeuristicLab.Collections;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.IntegerVectorEncoding;
6using HeuristicLab.Operators;
7using HeuristicLab.Optimization;
8using HeuristicLab.Parameters;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10using HeuristicLab.PluginInfrastructure;
11using System;
12using System.Linq;
13
14namespace HeuristicLab.BioBoost.Operators.Mutation {
15  [StorableClass]
16  public class MultiIntegerVectorManipulator : StochasticMultiBranch<IIntegerVectorManipulator>, IIntegerVectorManipulator, IStochasticOperator {
17
18    public override bool CanChangeName {
19      get { return false; }
20    }
21
22    protected override bool CreateChildOperation {
23      get { return true; }
24    }
25
26    public ILookupParameter<IntegerVector> IntegerVectorParameter {
27      get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; }
28    }
29    public IValueLookupParameter<IntMatrix> BoundsParameter {
30      get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
31    }
32
33    #region Construction & Cloning
34    [StorableConstructor]
35    protected MultiIntegerVectorManipulator(bool isDeserializing) : base(isDeserializing) {}
36    protected MultiIntegerVectorManipulator(MultiIntegerVectorManipulator orig, Cloner cloner) : base(orig, cloner) {}
37    public MultiIntegerVectorManipulator() {
38      Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The integer vector that is being manipulating."));
39      Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The lower and upper bounds for each dimension of the vector."));
40
41      foreach (var t in ApplicationManager.Manager.GetTypes(typeof(IIntegerVectorManipulator))) {
42        if (t == this.GetType()) continue; // avoid infinite recursion
43        IIntegerVectorManipulator instance = null;
44        try {
45          instance = Activator.CreateInstance(t) as IIntegerVectorManipulator;
46        } catch {}
47        if (instance != null) Operators.Add(instance);
48      }
49    }
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new MultiIntegerVectorManipulator(this, cloner);
52    }
53    #endregion
54
55    protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IIntegerVectorManipulator>> e) {
56      base.Operators_ItemsReplaced(sender, e);
57      ParameterizeManipulators();
58    }
59
60    protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IIntegerVectorManipulator>> e) {
61      base.Operators_ItemsAdded(sender, e);
62      ParameterizeManipulators();
63    }
64
65    private void ParameterizeManipulators() {
66      foreach (var op in Operators.OfType<IIntegerVectorManipulator>()) {
67        op.IntegerVectorParameter.ActualName = IntegerVectorParameter.Name;
68      }
69      foreach (var op in Operators.OfType<IBoundedIntegerVectorOperator>()) {
70        op.BoundsParameter.ActualName = BoundsParameter.Name;
71      }
72      foreach (var op in Operators.OfType<IStochasticOperator>()) {
73        op.RandomParameter.ActualName = RandomParameter.Name;
74      }
75    }
76
77    public override IOperation InstrumentedApply()
78    {
79        if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one real vector manipulator to choose from.");
80        return base.InstrumentedApply();
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.