(population, **args)
return population.bestFitness(lower)
The Roulette Wheel selector
The Roulette Wheel selector
The Roulette Wheel selector
def GRouletteWheel(population, **args):
   """ The Roulette Wheel selector """
   psum = None
   if args["popID"] != GRouletteWheel.cachePopID:
      GRouletteWheel.cachePopID = args["popID"]
      psum = GRouletteWheel_PrepareWheel(population)
      GRouletteWheel.cacheWheel = psum
   else:
      psum = GRouletteWheel.cacheWheel

   cutoff = random.random()
   lower = 0
   upper = len(population) - 1
   while(upper >= lower):
      i = lower + ((upper - lower) / 2)
      if psum[i] > cutoff:
         upper = i - 1
      else:
         lower = i + 1

   lower = min(len(population) - 1, lower)
   lower = max(0, lower)

   return population.bestFitness(lower)
def GRouletteWheel ( population , * * args ) : psum = None if args [ "popID" ] != GRouletteWheel . cachePopID : GRouletteWheel . cachePopID = args [ "popID" ] psum = GRouletteWheel_PrepareWheel ( population ) GRouletteWheel . cacheWheel = psum else : psum = GRouletteWheel . cacheWheel cutoff = random . random ( ) lower = 0 upper = len ( population ) - 1 while ( upper >= lower ) : i = lower + ( ( upper - lower ) / 2 ) if psum [ i ] > cutoff : upper = i - 1 else : lower = i + 1 lower = min ( len ( population ) - 1 , lower ) lower = max ( 0 , lower ) return population . bestFitness ( lower )