AA Applied Algorithms

Selection Methods

How a Genetic Algorithm picks parents — biased toward the fittest, but not deterministic.

Why we need them

In a GA we need to pick which individuals reproduce. If we always pick the very best, we lose diversity instantly. If we pick uniformly at random, fitness doesn't matter. We want something in between — fitter individuals get picked more often, but everyone has a chance.

Roulette wheel selection

The picture

Imagine a roulette wheel where each individual gets a slice proportional to its fitness. Higher fitness → bigger slice → more likely to be picked.

Five steps:

  1. Compute total fitness F = Σ fitness(i).
  2. Compute relative fitness for each: fitness(i) / F.
  3. Compute cumulative probabilities (running sum).
  4. Draw a random number r in [0, 1].
  5. Pick the first individual whose cumulative probability ≥ r.

Example 1: Graph coloring (maximization)

4 individuals, fitness = # of satisfied constraints:

Ind.FitnessRelativeCumulative
A1212/30 = 0.4000.400
B88/30 = 0.2670.667
C66/30 = 0.2000.867
D44/30 = 0.1331.000

Total = 30. Draw r = 0.52: 0.52 falls between A's cumulative (0.400) and B's (0.667) → select B.

Example 2: TSP (minimization)

For minimization (smaller distance = better), invert: fitness = 1 / distance.

TourDistanceFitness = 1/dP(select)Cumulative
A3000.00330.0670.067
B2500.00400.0890.156
C800.01250.2810.436
D400.02500.5621.000

Total fitness = 0.0445. Draw r = 0.35 → falls between B (0.156) and C (0.436) → select C.

Tournament selection

Even simpler: pick K random individuals from the population, return the best of those.

K-way tournament:
    pick K random individuals
    return argmax_fitness among them

Tuning K:

Tournament selection is popular because it:

Interactive demo

Spin the wheel several times — count how often each is picked. Try changing fitness values.

Click spin

Exam tips

Frequently asked

  • "Apply roulette wheel selection with these fitness values and r = 0.X" — compute total, relative, cumulative, find which slice r falls in.
  • "What if it's a minimization problem?" — use 1/cost as fitness, OR subtract each cost from max_cost + 1.
  • "What is K in tournament selection?" — number of competitors. Higher K = stronger selection pressure.
  • "Which has more diversity, tournament with K=2 or roulette wheel?" — usually tournament with K=2; less greedy than roulette wheel when one individual has much higher fitness.