Changeset 10483 for branches/LogResidualEvaluator/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/BiasedMultiVRPSolutionManipulator.cs
- Timestamp:
- 02/20/14 14:56:39 (10 years ago)
- Location:
- branches/LogResidualEvaluator
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LogResidualEvaluator
- Property svn:mergeinfo changed
-
branches/LogResidualEvaluator/HeuristicLab.Problems.VehicleRouting
- Property svn:mergeinfo changed
-
branches/LogResidualEvaluator/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/BiasedMultiVRPSolutionManipulator.cs
r9462 r10483 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; 32 using HeuristicLab.Random; 34 33 35 34 namespace HeuristicLab.Problems.VehicleRouting.Encodings.General { … … 40 39 get { return (ValueLookupParameter<DoubleArray>)Parameters["ActualProbabilities"]; } 41 40 } 42 41 43 42 public ValueLookupParameter<StringValue> SuccessProgressAnalyisis { 44 43 get { return (ValueLookupParameter<StringValue>)Parameters["SuccessProgressAnalysis"]; } … … 63 62 : base() { 64 63 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", 64 Parameters.Add(new ValueLookupParameter<StringValue>("SuccessProgressAnalysis", "The success progress analyisis to be considered", 66 65 new StringValue("ExecutedMutationOperator"))); 67 66 … … 69 68 Parameters.Add(new ValueParameter<DoubleValue>("LowerBound", "The depth of the individuals in the scope tree.", new DoubleValue(0.01))); 70 69 Parameters.Add(new ValueParameter<IntValue>("Depth", "The depth of the individuals in the scope tree.", new IntValue(1))); 70 71 SelectedOperatorParameter.ActualName = "SelectedManipulationOperator"; 71 72 } 72 73 … … 81 82 } 82 83 83 public override IOperation Apply() {84 public override IOperation InstrumentedApply() { 84 85 IOperator successor = null; 85 86 … … 133 134 } 134 135 135 //////////////// 136 //////////////// code has to be duplicated since ActualProbabilitiesParameter.ActualValue are updated and used for operator selection 136 137 IRandom random = RandomParameter.ActualValue; 137 138 DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue; … … 142 143 if (checkedOperators.Count() > 0) { 143 144 // 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 } 145 successor = 146 checkedOperators.SampleProportional(random, 1, probabilities, false, false).First().Value; 155 147 } 156 148
Note: See TracChangeset
for help on using the changeset viewer.