Changeset 3568 for trunk/sources/HeuristicLab.Operators/3.3
- Timestamp:
- 04/30/10 10:28:32 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Operators/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs
r3445 r3568 39 39 40 40 [Storable] 41 private ItemList<T> operators;42 public ItemList<T> Operators {41 private CheckedItemList<T> operators; 42 public CheckedItemList<T> Operators { 43 43 get { return operators; } 44 44 } … … 46 46 public MultiOperator() 47 47 : base() { 48 operators = new ItemList<T>();48 operators = new CheckedItemList<T>(); 49 49 Initialize(); 50 50 } … … 65 65 public override IDeepCloneable Clone(Cloner cloner) { 66 66 MultiOperator<T> clone = (MultiOperator<T>)base.Clone(cloner); 67 clone.operators = ( ItemList<T>)cloner.Clone(operators);67 clone.operators = (CheckedItemList<T>)cloner.Clone(operators); 68 68 clone.Initialize(); 69 69 return clone; -
trunk/sources/HeuristicLab.Operators/3.3/StochasticMultiOperator.cs
r3527 r3568 113 113 /// </summary> 114 114 /// <exception cref="InvalidOperationException">Thrown when the list of probabilites does not 115 /// match the number of operators.</exception> 115 /// match the number of operators, the list of selected operators is empty, 116 /// or all selected operators have zero probabitlity.</exception> 116 117 /// <returns>A new operation with the operator that was selected followed by the current operator's successor.</returns> 117 118 public override IOperation Apply() { 118 119 IRandom random = RandomParameter.ActualValue; 119 120 DoubleArray probabilities = ProbabilitiesParameter.ActualValue; 120 if (probabilities.Length != Operators.Count) {121 if (probabilities.Length != Operators.Count) { 121 122 throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators"); 122 123 } 123 double sum = 0;124 for (int i = 0; i < Operators.Count; i++) {125 sum += probabilities[i];124 var checkedOperators = Operators.CheckedItems; 125 if (checkedOperators.Count() == 0) { 126 throw new InvalidOperationException(Name + ": At least one operator must be checked."); 126 127 } 128 double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum(); 129 if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability."); 127 130 double r = random.NextDouble() * sum; 128 131 sum = 0; 129 132 IOperator successor = null; 130 for (int i = 0; i < Operators.Count; i++) {131 sum += probabilities[i ];132 if (sum > r) {133 successor = Operators[i];133 foreach (var indexedItem in checkedOperators) { 134 sum += probabilities[indexedItem.Index]; 135 if (sum > r) { 136 successor = indexedItem.Value; 134 137 break; 135 138 }
Note: See TracChangeset
for help on using the changeset viewer.