Method: EvoSynth::Selections::RouletteWheelSelection#select

Defined in:
lib/evosynth/operators/selections/roulette_wheel_selection.rb

#select(population, select_count = 1) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/evosynth/operators/selections/roulette_wheel_selection.rb', line 33

def select(population, select_count = 1)
  selected_population = EvoSynth::Population.new
  fitness_hash = generate_fitness_hash(population)

  limit = EvoSynth.rand(fitness_hash[population.size - 1] / select_count)

  select_count.to_i.times do
    next_individual = select_next_individual(population, limit, fitness_hash)
    selected_population.add(next_individual)
    limit += fitness_hash[population.size - 1] / select_count
  end

  selected_population
end