Changeset 10474 for trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers
- Timestamp:
- 02/20/14 13:15:22 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/BiasedMultiVRPSolutionCrossover.cs
r10472 r10474 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Random; 32 33 33 34 namespace HeuristicLab.Problems.VehicleRouting.Encodings.General { … … 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 = checkedOperators.SampleProportional(random, 1, probabilities, false, false).First().Value; 155 146 } 156 147
Note: See TracChangeset
for help on using the changeset viewer.