Class: TournamentPickStrategy
- Inherits:
-
PickStrategy
- Object
- PickStrategy
- TournamentPickStrategy
- Defined in:
- lib/gimuby/genetic/population/pick_strategy/tournament_pick_strategy.rb
Instance Attribute Summary
Attributes inherited from PickStrategy
Instance Method Summary collapse
Methods inherited from PickStrategy
Constructor Details
This class inherits a constructor from PickStrategy
Instance Method Details
#pick(population) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gimuby/genetic/population/pick_strategy/tournament_pick_strategy.rb', line 5 def pick(population) solutions = population.solutions number = get_number_to_pick(population) candidates = solutions.clone while candidates.length > number sol1 = Factory.random_entry(candidates) sol2 = sol1 while sol1 == sol2 sol2 = Factory.random_entry(candidates) end if population.get_fitness(sol1) < population.get_fitness(sol2) candidates.delete(sol2) else candidates.delete(sol1) end end candidates end |