Tournament selection chooses parents for a genetic algorithm by randomly challenging a fixed number of chromosomes and selecting the participant with the highest fitness. The tournament size controls how many candidates compete. section 5.3
A tournament with four participants
With SelectionType.tournament(4), the algorithm samples four population members, compares their fitness values, and returns the fittest one as a parent. It repeats the process independently to choose a second parent. section 5.3
An implementation proceeds through these steps:
- Store tournament selection as a configurable selection type, with its associated value representing the number of participants. section 5.3
- Choose random population indexes and compare their cached fitness values. section 5.3
- Keep the best participant and pass selected parents to reproduction, crossover, and later mutation. section 5.3
// find k random individuals in the population and pick the best one
private func pickTournament(numParticipants: UInt) -> ChromosomeType {
var best: ChromosomeType = ChromosomeType.randomInstance()
var bestFitness: Double = best.fitness
for _ in 0..<numParticipants { // find the best participant
let test = Int(arc4random_uniform(UInt32(population.count)))
if fitnessCache[test] > bestFitness {
bestFitness = fitnessCache[test]
best = population[test]
}
}
return best
}
The implementation shows the compact tournament loop: initialize a candidate, sample population members, replace the candidate when a higher fitness appears, and return the winner. section 5.3
Tournament selection is paired with roulette-wheel selection as a configurable alternative. Roulette selection weights every chromosome by its share of total fitness; tournament selection instead makes local competitions among random candidates. section 5.3
A useful extension lets a tournament sometimes choose the second- or third-best chromosome using diminishing probabilities, preserving more variation than always selecting the winner. section 5.8



