Module: SelectionMethods
- Included in:
- GA
- Defined in:
- lib/selection_methods.rb
Instance Method Summary collapse
Instance Method Details
#two_tournament ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/selection_methods.rb', line 2 def two_tournament idx1 = rand(@population.size) idx2 = rand(@population.size) while idx1==idx2 idx2 = rand(@population.size) end @population[idx1].fitness = @fitness.call @population[idx1] @population[idx2].fitness = @fitness.call @population[idx2] return ((@population[idx1].fitness) < (@population[idx2].fitness)) ? idx1 : idx2 end |