Module: GladiatorialSelection
- Defined in:
- lib/charlie/selection.rb
Overview
Co-evolution: Direct competition (gladiatorial) selection. Define a Genotype#fight function to use this
Instance Method Summary collapse
Instance Method Details
#next_generation(population) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/charlie/selection.rb', line 172 def next_generation(population) (population.size/2).times{ ix=[0,0,0,0] ix=(0..3).map{population.rand_index} while ix.uniq.size < 4 ix[0],ix[1] = ix[1],ix[0] unless population[ix[0]].fight(population[ix[1]]) # 0 and 2 hold winners ix[2],ix[3] = ix[3],ix[2] unless population[ix[2]].fight(population[ix[3]]) nw = []; nw += yield(population[ix[0]],population[ix[2]]) while nw.size < 2 population[ix[1]],population[ix[3]] = *nw } population end |