Roulette-wheel selection chooses parents for a genetic algorithm by giving each chromosome a share of the selection probability proportional to its fitness. A fitter candidate has a larger share, but a weaker candidate can still be chosen. This makes selection probabilistic rather than a rule that always takes the best individuals. section 7.3.3
To select a parent:
- Add the fitness values of all chromosomes to get total fitness F. section 7.3.3
- For each chromosome k, calculate its probability pₖ = f(xₖ) / F, then its cumulative probability qₖ by adding probabilities through k. section 7.3.3
- Draw r from [0, 1] and choose the first chromosome whose cumulative probability reaches r. Repeat the draw for each parent needed. section 7.3.3 section 7.4
Ticket-price candidates
Five candidate prices have fitness values 8,820, 84,420, 90,000, 128,500, and 18,000, totaling 329,740. The fourth candidate has the largest selection probability, about 0.39. With the cumulative probabilities shown for these candidates, a draw of 0.25 selects the second; a draw of 0.58 selects the fourth. Neither draw simply takes the highest-ranked candidate. section 7.3.3
Table 7.5 Cumulative probabilities (view table figure)
| Candidate solutions x |
Values of x in the solution space |
Candidate solutions in the binary coding space |
Objective function f(x) |
Selection probability pk |
Cumulative probability qk |
|---|---|---|---|---|---|
| x1 |
77 |
01001101 |
8,820 |
0.03 |
0.03 |
| x2 |
203 |
11001011 |
84,420 |
0.26 |
0.28 |
| x3 |
110 |
01101110 |
90,000 |
0.27 |
0.56 |
| x4 |
145 |
10010001 |
128,500 |
0.39 |
0.95 |
| x5 |
230 |
11100110 |
18,000 |
0.05 |
1.00 |
The table places each candidate’s fitness, selection probability, and cumulative probability side by side; the cumulative column determines which candidate a random draw selects. section 7.3.3
In Python, `roulette_wheel_selection(population, num_parents)` scores the population, divides each fitness by the total, and makes a fresh `random.random()` draw for every requested parent. It accumulates probabilities until one exceeds the draw. This is an alternative to `select_parent`, which uses equal-chance random sampling; the shown genetic-algorithm loop calls that random-sampling function, so using roulette-wheel selection there requires replacing the call. section 7.4
def roulette_wheel_selection(population, num_parents):
fitness_values, population = fitness_score(population) #1
total_fitness = sum(fitness_values)
probabilities = [fitness / total_fitness for fitness in fitness_values]#2
selected_parents = []
for i in range(num_parents): #3
r = random.random() #4
cumulative_probability = 0 #5
for j in range(len(population)):
cumulative_probability += probabilities[j]
if cumulative_probability > r:
selected_parents.append(population[j])
break
return selected_parents
The Python function shows fitness normalization, repeated random draws, and the cumulative-probability scan used to return selected parents. section 7.4
The trade-off is selective pressure: a very fit individual can contribute disproportionately to offspring, reducing population diversity. Inspect the fitness shares when deciding whether this proportional method suits the population. section 7.3.3



