Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/14 13:15:22 (11 years ago)
Author:
gkronber
Message:

#2119: using RandomEnumerable.SampleProportional in BiasedMultiVRPOperators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/BiasedMultiVRPSolutionCrossover.cs

    r10472 r10474  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Random;
    3233
    3334namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
     
    142143      if (checkedOperators.Count() > 0) {
    143144        // 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;
    155146      }
    156147
Note: See TracChangeset for help on using the changeset viewer.