Class: EvoSynth::Selections::NStageTournamentSelection
- Inherits:
-
Object
- Object
- EvoSynth::Selections::NStageTournamentSelection
- Defined in:
- lib/evosynth/operators/selections/n_stage_tournament_selection.rb
Overview
Q-STUFIGE-TURNIER-SELEKTION (Weicker Page 69)
Constant Summary collapse
- DEFAULT_STAGES =
2
Instance Attribute Summary collapse
-
#stages ⇒ Object
Returns the value of attribute stages.
Instance Method Summary collapse
-
#initialize(stages = DEFAULT_STAGES) ⇒ NStageTournamentSelection
constructor
A new instance of NStageTournamentSelection.
- #select(population, select_count = 1) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(stages = DEFAULT_STAGES) ⇒ NStageTournamentSelection
Returns a new instance of NStageTournamentSelection.
37 38 39 |
# File 'lib/evosynth/operators/selections/n_stage_tournament_selection.rb', line 37 def initialize(stages = DEFAULT_STAGES) @stages = stages end |
Instance Attribute Details
#stages ⇒ Object
Returns the value of attribute stages.
33 34 35 |
# File 'lib/evosynth/operators/selections/n_stage_tournament_selection.rb', line 33 def stages @stages end |
Instance Method Details
#select(population, select_count = 1) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/evosynth/operators/selections/n_stage_tournament_selection.rb', line 41 def select(population, select_count = 1) selected_population = EvoSynth::Population.new scores = calculate_scores(population) scores = scores.sort { |first, second| first[0] <=> second[0] * -1 } scores.first(select_count).each { |winner| selected_population.add(winner[1]) } selected_population end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/evosynth/operators/selections/n_stage_tournament_selection.rb', line 51 def to_s "n-stage tournament selection <stages: #{@stages}>" end |