- Timestamp:
- 01/07/14 13:13:41 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Creators/MultiVRPSolutionCreator.cs
r9456 r10295 97 97 } 98 98 99 public override IOperation Apply() {99 public override IOperation InstrumentedApply() { 100 100 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one VRP creator to choose from."); 101 return base. Apply();101 return base.InstrumentedApply(); 102 102 } 103 103 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/BiasedMultiVRPSolutionCrossover.cs
r9462 r10295 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 using System.Text; 24 using HeuristicLab.Analysis; 25 using HeuristicLab.Collections; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 27 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Common;29 using HeuristicLab.Analysis;30 using HeuristicLab.Parameters;31 using HeuristicLab.Optimization;32 using HeuristicLab.Data;33 using HeuristicLab.Collections;34 32 35 33 namespace HeuristicLab.Problems.VehicleRouting.Encodings.General { … … 81 79 } 82 80 83 public override IOperation Apply() {81 public override IOperation InstrumentedApply() { 84 82 IOperator successor = null; 85 83 … … 133 131 } 134 132 135 //////////////// 136 IRandom random = RandomParameter.ActualValue; 137 DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue; 138 if (probabilities.Length != Operators.Count) { 139 throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators"); 140 } 141 var checkedOperators = Operators.CheckedItems; 142 if (checkedOperators.Count() > 0) { 143 // select a random operator from the checked operators 144 double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum(); 145 if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability."); 146 double r = random.NextDouble() * sum; 147 sum = 0; 148 foreach (var indexedItem in checkedOperators) { 149 sum += probabilities[indexedItem.Index]; 150 if (sum > r) { 151 successor = indexedItem.Value; 152 break; 153 } 154 } 155 } 156 157 IOperation successorOp = null; 158 if (Successor != null) 159 successorOp = ExecutionContext.CreateOperation(Successor); 160 OperationCollection next = new OperationCollection(successorOp); 161 if (successor != null) { 162 SelectedOperatorParameter.ActualValue = new StringValue(successor.Name); 163 164 if (CreateChildOperation) 165 next.Insert(0, ExecutionContext.CreateChildOperation(successor)); 166 else next.Insert(0, ExecutionContext.CreateOperation(successor)); 167 } else { 168 SelectedOperatorParameter.ActualValue = new StringValue(""); 169 } 170 171 return next; 133 return base.InstrumentedApply(); 172 134 } 173 135 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/MultiVRPSolutionCrossover.cs
r9456 r10295 106 106 } 107 107 108 public override IOperation Apply() {108 public override IOperation InstrumentedApply() { 109 109 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation crossover to choose from."); 110 return base. Apply();110 return base.InstrumentedApply(); 111 111 } 112 112 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/BiasedMultiVRPSolutionManipulator.cs
r9462 r10295 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 using System.Text; 24 using HeuristicLab.Analysis; 25 using HeuristicLab.Collections; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 27 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Common;29 using HeuristicLab.Analysis;30 using HeuristicLab.Parameters;31 using HeuristicLab.Optimization;32 using HeuristicLab.Data;33 using HeuristicLab.Collections;34 32 35 33 namespace HeuristicLab.Problems.VehicleRouting.Encodings.General { … … 40 38 get { return (ValueLookupParameter<DoubleArray>)Parameters["ActualProbabilities"]; } 41 39 } 42 40 43 41 public ValueLookupParameter<StringValue> SuccessProgressAnalyisis { 44 42 get { return (ValueLookupParameter<StringValue>)Parameters["SuccessProgressAnalysis"]; } … … 63 61 : base() { 64 62 Parameters.Add(new ValueLookupParameter<DoubleArray>("ActualProbabilities", "The array of relative probabilities for each operator.")); 65 Parameters.Add(new ValueLookupParameter<StringValue>("SuccessProgressAnalysis", "The success progress analyisis to be considered", 63 Parameters.Add(new ValueLookupParameter<StringValue>("SuccessProgressAnalysis", "The success progress analyisis to be considered", 66 64 new StringValue("ExecutedMutationOperator"))); 67 65 … … 81 79 } 82 80 83 public override IOperation Apply() {81 public override IOperation InstrumentedApply() { 84 82 IOperator successor = null; 85 83 … … 133 131 } 134 132 135 //////////////// 136 IRandom random = RandomParameter.ActualValue; 137 DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue; 138 if (probabilities.Length != Operators.Count) { 139 throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators"); 140 } 141 var checkedOperators = Operators.CheckedItems; 142 if (checkedOperators.Count() > 0) { 143 // select a random operator from the checked operators 144 double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum(); 145 if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability."); 146 double r = random.NextDouble() * sum; 147 sum = 0; 148 foreach (var indexedItem in checkedOperators) { 149 sum += probabilities[indexedItem.Index]; 150 if (sum > r) { 151 successor = indexedItem.Value; 152 break; 153 } 154 } 155 } 156 157 IOperation successorOp = null; 158 if (Successor != null) 159 successorOp = ExecutionContext.CreateOperation(Successor); 160 OperationCollection next = new OperationCollection(successorOp); 161 if (successor != null) { 162 SelectedOperatorParameter.ActualValue = new StringValue(successor.Name); 163 164 if (CreateChildOperation) 165 next.Insert(0, ExecutionContext.CreateChildOperation(successor)); 166 else next.Insert(0, ExecutionContext.CreateOperation(successor)); 167 } else { 168 SelectedOperatorParameter.ActualValue = new StringValue(""); 169 } 170 171 return next; 133 return base.InstrumentedApply(); 172 134 } 173 135 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/MultiVRPSolutionManipulator.cs
r9456 r10295 97 97 } 98 98 99 public override IOperation Apply() {99 public override IOperation InstrumentedApply() { 100 100 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation manipulator to choose from."); 101 return base. Apply();101 return base.InstrumentedApply(); 102 102 } 103 103 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/MultiVRPMoveOperator/MultiVRPMoveGenerator.cs
r9456 r10295 153 153 } 154 154 155 public override IOperation Apply() {155 public override IOperation InstrumentedApply() { 156 156 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one VRP move generator choose from."); 157 OperationCollection next = new OperationCollection(base. Apply());157 OperationCollection next = new OperationCollection(base.InstrumentedApply()); 158 158 159 159 for (int i = 0; i < SelectedOperatorsParameter.ActualValue.Value; i++) {
Note: See TracChangeset
for help on using the changeset viewer.