Class: EvoSynth::Selections::TournamentSelection
- Inherits:
-
Object
- Object
- EvoSynth::Selections::TournamentSelection
- Defined in:
- lib/evosynth/operators/selections/tournament_selection.rb
Overview
TURNIER-SELEKTION (Weicker Page 76)
Constant Summary collapse
- DEFAULT_ENEMIES =
2
Instance Attribute Summary collapse
-
#enemies ⇒ Object
Returns the value of attribute enemies.
Instance Method Summary collapse
-
#initialize(enemies = DEFAULT_ENEMIES) ⇒ TournamentSelection
constructor
A new instance of TournamentSelection.
- #select(population, select_count = 1) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(enemies = DEFAULT_ENEMIES) ⇒ TournamentSelection
37 38 39 |
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 37 def initialize(enemies = DEFAULT_ENEMIES) @enemies = enemies end |
Instance Attribute Details
#enemies ⇒ Object
Returns the value of attribute enemies.
33 34 35 |
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 33 def enemies @enemies end |
Instance Method Details
#select(population, select_count = 1) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 41 def select(population, select_count = 1) selected_population = EvoSynth::Population.new select_count.to_i.times do individual = fight(population, population[EvoSynth.rand(population.size)]) selected_population.add(individual) end selected_population end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 52 def to_s "tournament selection <enemies: #{@enemies}>" end |