Changeset 3445
- Timestamp:
- 04/20/10 16:35:42 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/MultiBinaryVectorCrossover.cs
r3425 r3445 31 31 [Item("MultiBinaryVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 32 32 [StorableClass] 33 public class MultiBinaryVectorCrossover : StochasticMultiOperator<IBinaryVectorCrossover>, IBinaryVectorCrossover {33 public class MultiBinaryVectorCrossover : StochasticMultiOperator<IBinaryVectorCrossover>, IBinaryVectorCrossover, IStochasticOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 37 protected override bool CreateChildOperation { 38 get { return true; }39 }40 public override bool AutomaticTypeDiscovery {41 38 get { return true; } 42 39 } … … 58 55 Parameters.Add(new LookupParameter<BinaryVector>("Child", "The child binary vector resulting from the crossover.")); 59 56 ChildParameter.ActualName = "BinaryVector"; 57 } 60 58 61 Initialize(); 59 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IBinaryVectorCrossover>> e) { 60 base.Operators_ItemsReplaced(sender, e); 62 61 ParameterizeCrossovers(); 63 62 } 64 63 65 [StorableHook(HookType.AfterDeserialization)] 66 private void Initialize() { 67 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IBinaryVectorCrossover>>(Operators_ItemsAdded); 68 Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IBinaryVectorCrossover>>(Operators_ItemsReplaced); 69 } 70 71 private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IBinaryVectorCrossover>> e) { 72 ParameterizeCrossovers(); 73 } 74 75 private void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IBinaryVectorCrossover>> e) { 64 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IBinaryVectorCrossover>> e) { 65 base.Operators_ItemsAdded(sender, e); 76 66 ParameterizeCrossovers(); 77 67 } -
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs
r3425 r3445 31 31 [Item("MultiIntegerVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 32 32 [StorableClass] 33 public class MultiIntegerVectorCrossover : StochasticMultiOperator<IIntegerVectorCrossover>, IIntegerVectorCrossover {33 public class MultiIntegerVectorCrossover : StochasticMultiOperator<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 37 protected override bool CreateChildOperation { 38 get { return true; }39 }40 public override bool AutomaticTypeDiscovery {41 38 get { return true; } 42 39 } … … 58 55 Parameters.Add(new LookupParameter<IntegerVector>("Child", "The child integer vector resulting from the crossover.")); 59 56 ChildParameter.ActualName = "IntegerVector"; 57 } 60 58 61 Initialize(); 59 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IIntegerVectorCrossover>> e) { 60 base.Operators_ItemsReplaced(sender, e); 62 61 ParameterizeCrossovers(); 63 62 } 64 63 65 [StorableHook(HookType.AfterDeserialization)] 66 private void Initialize() { 67 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IIntegerVectorCrossover>>(Operators_ItemsAdded); 68 Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IIntegerVectorCrossover>>(Operators_ItemsReplaced); 69 } 70 71 private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IIntegerVectorCrossover>> e) { 72 ParameterizeCrossovers(); 73 } 74 75 private void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IIntegerVectorCrossover>> e) { 64 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IIntegerVectorCrossover>> e) { 65 base.Operators_ItemsAdded(sender, e); 76 66 ParameterizeCrossovers(); 77 67 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Crossovers/MultiPermutationCrossover.cs
r3425 r3445 31 31 [Item("MultiPermutationCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 32 32 [StorableClass] 33 public class MultiPermutationCrossover : StochasticMultiOperator<IPermutationCrossover>, IPermutationCrossover {33 public class MultiPermutationCrossover : StochasticMultiOperator<IPermutationCrossover>, IPermutationCrossover, IStochasticOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 37 protected override bool CreateChildOperation { 38 get { return true; }39 }40 public override bool AutomaticTypeDiscovery {41 38 get { return true; } 42 39 } … … 58 55 Parameters.Add(new LookupParameter<Permutation>("Child", "The child permutation resulting from the crossover.")); 59 56 ChildParameter.ActualName = "Permutation"; 57 } 60 58 61 Initialize(); 59 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) { 60 base.Operators_ItemsReplaced(sender, e); 62 61 ParameterizeCrossovers(); 63 62 } 64 63 65 [StorableHook(HookType.AfterDeserialization)] 66 private void Initialize() { 67 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IPermutationCrossover>>(Operators_ItemsAdded); 68 Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IPermutationCrossover>>(Operators_ItemsReplaced); 69 } 70 71 private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) { 72 ParameterizeCrossovers(); 73 } 74 75 private void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) { 64 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) { 65 base.Operators_ItemsAdded(sender, e); 76 66 ParameterizeCrossovers(); 77 67 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/MultiPermutationManipulator.cs
r3425 r3445 31 31 [Item("MultiPermutationManipulator", "Randomly selects and applies one of its manipulators every time it is called.")] 32 32 [StorableClass] 33 public class MultiPermutationManipulator : StochasticMultiOperator<IPermutationManipulator>, IPermutationManipulator {33 public class MultiPermutationManipulator : StochasticMultiOperator<IPermutationManipulator>, IPermutationManipulator, IStochasticOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } 36 36 } 37 37 protected override bool CreateChildOperation { 38 get { return true; }39 }40 public override bool AutomaticTypeDiscovery {41 38 get { return true; } 42 39 } … … 51 48 : base() { 52 49 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that is being manipulating.")); 50 } 53 51 54 Initialize(); 52 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationManipulator>> e) { 53 base.Operators_ItemsReplaced(sender, e); 55 54 ParameterizeManipulators(); 56 55 } 57 56 58 [StorableHook(HookType.AfterDeserialization)] 59 private void Initialize() { 60 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IPermutationManipulator>>(Operators_ItemsAdded); 61 Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IPermutationManipulator>>(Operators_ItemsReplaced); 62 } 63 64 private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationManipulator>> e) { 65 ParameterizeManipulators(); 66 } 67 68 private void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationManipulator>> e) { 57 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationManipulator>> e) { 58 base.Operators_ItemsAdded(sender, e); 69 59 ParameterizeManipulators(); 70 60 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/MultiRealVectorCrossover.cs
r3425 r3445 32 32 [Item("MultiRealVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 33 33 [StorableClass] 34 public class MultiRealVectorCrossover : StochasticMultiOperator<IRealVectorCrossover>, IRealVectorCrossover {34 public class MultiRealVectorCrossover : StochasticMultiOperator<IRealVectorCrossover>, IRealVectorCrossover, IStochasticOperator { 35 35 public override bool CanChangeName { 36 36 get { return false; } 37 37 } 38 38 protected override bool CreateChildOperation { 39 get { return true; }40 }41 public override bool AutomaticTypeDiscovery {42 39 get { return true; } 43 40 } … … 62 59 ChildParameter.ActualName = "RealVector"; 63 60 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the vector.")); 61 } 64 62 65 Initialize(); 63 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorCrossover>> e) { 64 base.Operators_ItemsReplaced(sender, e); 66 65 ParameterizeCrossovers(); 67 66 } 68 67 69 [StorableHook(HookType.AfterDeserialization)] 70 private void Initialize() { 71 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IRealVectorCrossover>>(Operators_ItemsAdded); 72 Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IRealVectorCrossover>>(Operators_ItemsReplaced); 73 } 74 75 private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorCrossover>> e) { 76 ParameterizeCrossovers(); 77 } 78 79 private void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorCrossover>> e) { 68 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorCrossover>> e) { 69 base.Operators_ItemsAdded(sender, e); 80 70 ParameterizeCrossovers(); 81 71 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MultiRealVectorManipulator.cs
r3425 r3445 32 32 [Item("MultiRealVectorManipulator", "Randomly selects and applies one of its manipulators every time it is called.")] 33 33 [StorableClass] 34 public class MultiRealVectorManipulator : StochasticMultiOperator<IRealVectorManipulator>, IRealVectorManipulator {34 public class MultiRealVectorManipulator : StochasticMultiOperator<IRealVectorManipulator>, IRealVectorManipulator, IStochasticOperator { 35 35 public override bool CanChangeName { 36 36 get { return false; } 37 37 } 38 38 protected override bool CreateChildOperation { 39 get { return true; }40 }41 public override bool AutomaticTypeDiscovery {42 39 get { return true; } 43 40 } … … 56 53 Parameters.Add(new LookupParameter<RealVector>("RealVector", "The real vector that is being manipulating.")); 57 54 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the vector.")); 55 } 58 56 59 Initialize(); 57 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorManipulator>> e) { 58 base.Operators_ItemsReplaced(sender, e); 60 59 ParameterizeManipulators(); 61 60 } 62 61 63 [StorableHook(HookType.AfterDeserialization)] 64 private void Initialize() { 65 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IRealVectorManipulator>>(Operators_ItemsAdded); 66 Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IRealVectorManipulator>>(Operators_ItemsReplaced); 67 } 68 69 private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorManipulator>> e) { 70 ParameterizeManipulators(); 71 } 72 73 private void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorManipulator>> e) { 62 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRealVectorManipulator>> e) { 63 base.Operators_ItemsAdded(sender, e); 74 64 ParameterizeManipulators(); 75 65 } -
trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs
r3407 r3445 86 86 #region Events 87 87 private void RegisterOperatorsEvents() { 88 operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsAdded);89 operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsRemoved);90 operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsReplaced);91 operators.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsMoved);92 operators.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_CollectionReset);88 operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsAdded); 89 operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsRemoved); 90 operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsReplaced); 91 operators.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsMoved); 92 operators.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_CollectionReset); 93 93 } 94 94 private void DeregisterOperatorsEvents() { 95 operators.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsAdded);96 operators.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsRemoved);97 operators.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsReplaced);98 operators.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_ItemsMoved);99 operators.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>( operators_CollectionReset);95 operators.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsAdded); 96 operators.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsRemoved); 97 operators.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsReplaced); 98 operators.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsMoved); 99 operators.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_CollectionReset); 100 100 } 101 pr ivate void operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {101 protected virtual void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 102 102 UpdateOperatorParameters(); 103 103 } 104 pr ivate void operators_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {104 protected virtual void Operators_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 105 105 UpdateOperatorParameters(); 106 106 } 107 pr ivate void operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {107 protected virtual void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 108 108 foreach (IndexedItem<T> item in e.Items) 109 109 operatorParameters[item.Index].Value = item.Value; 110 110 } 111 pr ivate void operators_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {111 protected virtual void Operators_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 112 112 foreach (IndexedItem<T> item in e.Items) 113 113 operatorParameters[item.Index].Value = item.Value; 114 114 } 115 pr ivate void operators_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {115 protected virtual void Operators_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 116 116 UpdateOperatorParameters(); 117 117 } -
trunk/sources/HeuristicLab.Operators/3.3/StochasticMultiOperator.cs
r3425 r3445 38 38 public abstract class StochasticMultiOperator<T> : MultiOperator<T> where T : class, IOperator { 39 39 /// <summary> 40 /// Returns false by default. If this is overriden to return true, there will be an automatic type discovery41 /// of all instantiable types of T (except the own type) and instances will be added to the Operators list.42 /// </summary>43 public virtual bool AutomaticTypeDiscovery { get { return false; } }44 /// <summary>45 40 /// Should return true if the StochasticMultiOperator should create a new child operation with the selected successor 46 41 /// or if it should create a new operation. If you need to shield the parameters of the successor you should return true here. … … 70 65 Parameters.Add(new ValueLookupParameter<DoubleArray>("Probabilities", "The array of relative probabilities for each operator.", new DoubleArray())); 71 66 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 72 Initialize();73 67 } 74 68 75 [StorableHook(HookType.AfterDeserialization)] 76 private void Initialize() { 77 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsAdded); 78 Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsRemoved); 79 Operators.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Operators_ItemsMoved); 80 if (AutomaticTypeDiscovery) { 81 IEnumerable<Type> types = ApplicationManager.Manager.GetTypes(typeof(T), true); 82 foreach (Type type in types.OrderBy(x => x.FullName)) { 83 if (type != this.GetType()) 84 Operators.Add((T)Activator.CreateInstance(type)); 85 } 86 } 87 } 88 89 void Operators_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 90 if (Probabilities != null) { 91 DoubleArray oldProb = (DoubleArray)Probabilities.Clone(); 92 foreach (IndexedItem<T> old in e.OldItems) { 93 foreach (IndexedItem<T> item in e.Items) { 94 if (old.Value == item.Value && item.Index < Probabilities.Length && old.Index < oldProb.Length) 95 Probabilities[item.Index] = oldProb[old.Index]; 96 } 97 } 98 } 99 } 100 101 void Operators_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 69 protected override void Operators_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 70 base.Operators_ItemsRemoved(sender, e); 102 71 if (Probabilities != null && Probabilities.Length > Operators.Count) { 103 72 List<double> probs = new List<double>(Probabilities.Cast<double>()); … … 109 78 } 110 79 111 private void Operators_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 80 protected override void Operators_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 81 base.Operators_ItemsAdded(sender, e); 112 82 if (Probabilities != null && Probabilities.Length < Operators.Count) { 113 83 DoubleArray probs = new DoubleArray(Operators.Count); 114 84 double avg = 0; 115 85 if (Probabilities.Length > 0) { 116 for (int i = 0; i < Probabilities.Length; i++) 117 avg += Probabilities[i]; 118 avg /= (double)Probabilities.Length; 86 int zeros = 0; 87 for (int i = 0; i < Probabilities.Length; i++) { 88 if (Probabilities[i] == 0) zeros++; 89 else avg += Probabilities[i]; 90 } 91 if (Probabilities.Length - zeros > 0) 92 avg /= (double)(Probabilities.Length - zeros); 93 else avg = 1; 119 94 } else avg = 1; 120 95
Note: See TracChangeset
for help on using the changeset viewer.