1 | using HeuristicLab.Collections;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
6 | using HeuristicLab.Operators;
|
---|
7 | using HeuristicLab.Optimization;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 | using HeuristicLab.PluginInfrastructure;
|
---|
11 | using System;
|
---|
12 | using System.Linq;
|
---|
13 |
|
---|
14 | namespace 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 | }
|
---|