Nature solves hard optimisation problems by evolution. Evolutionary algorithms borrow its methods: a population of candidates, selection of the fittest, recombination and random mutation.

Evolutionary Algorithms

An evolutionary algorithm (EA) is a population-based, stochastic search inspired by Darwin's natural selection ("survival of the fittest"). A population of candidate solutions evolves over generations: better candidates are more likely to be chosen as parents, their offspring are created by recombination and mutation, and the new population replaces the old. EAs need no gradient and few assumptions, and they cope well with large, rugged search spaces where hill climbing gets stuck. Families include genetic algorithms, genetic programming, evolution strategies and evolutionary programming.

Genetic Algorithm Components

A genetic algorithm (GA) (Holland, 1975) encodes each candidate as a chromosome, commonly a bit string such as 11010011, made of genes. The main components are: encoding; an initial random population; a fitness function that scores each chromosome (higher is better); selection of parents, by roulette wheel (probability proportional to fitness), tournament or rank; crossover that exchanges parts of two parents at a chosen point to make children (single-point, two-point, uniform); mutation that flips each bit with a small probability (such as 0.001–0.01) to maintain diversity; and elitism, carrying the best individuals unchanged to the next generation. The loop of selection, crossover and mutation is repeated until a termination condition holds: a maximum number of generations, a good enough fitness, or no improvement.

Definition: Genetic algorithm. A population-based search that evolves bit-string chromosomes over generations using fitness-proportional selection, crossover and mutation to find a good solution to an optimisation problem.

Applications and Issues

Applications in AI: function and parameter optimisation, scheduling and timetabling, travelling salesman and routing, neural network design and training, feature selection in machine learning, game strategies, robot path planning, antenna and circuit design, and evolutionary art. Issues: premature convergence to a local optimum when diversity is lost, tuning of population size and rates, and the need for a good encoding. GAs give good, not guaranteed optimal, solutions.

Table 2.9: Genetic algorithm operators

Operator Action Purpose
Selection Choose parents by fitness Favour good solutions
Crossover Swap parts of two parents Combine good features
Mutation Flip random bits Maintain diversity
Elitism Keep best unchanged Never lose the best

Example 2.9: One generation by hand

Problem: Fitness f(x) = number of 1s in an 8-bit string. Parents P1 = 11010011 and P2 = 01101100. Cross over after bit 3. Find the children and fitness values; then compute roulette probabilities for four strings with fitness 169, 576, 64 and 361.

Solution:

  1. P1 = 110|10011, P2 = 011|01100. Fitness: P1 = 5, P2 = 4.
  2. Child 1 = 110|01100 = 11001100 (fitness 4); Child 2 = 011|10011 = 01110011 (fitness 5).
  3. Roulette: total fitness = 169 + 576 + 64 + 361 = 1,170. Probabilities: 0.144, 0.492, 0.055, 0.309.

Result: Children 11001100 and 01110011; the fittest string (576) is selected with probability 0.49.

p1, p2 = "11010011", "01101100"
cut = 3
c1, c2 = p1[:cut] + p2[cut:], p2[:cut] + p1[cut:]
print("children:", c1, c2)
print("fitness:", [s.count("1") for s in (p1, p2, c1, c2)])
fit = [169, 576, 64, 361]
print("probabilities:", [round(f / sum(fit), 3) for f in fit])

Output

children: 11001100 01110011
fitness: [5, 4, 4, 5]
probabilities: [0.144, 0.492, 0.055, 0.309]

Common mistakes

  • Setting the mutation rate so high that the search becomes random.
  • Using a fitness function that does not reflect the real objective.
  • Losing diversity through a tiny population and converging prematurely.
  • Expecting a genetic algorithm to guarantee the global optimum.

Key takeaways

  • GA: population of chromosomes; selection, crossover, mutation; repeat over generations.
  • Roulette selection probability = fitness / total fitness.
  • Mutation keeps diversity; elitism preserves the best.
  • Applications: optimisation, scheduling, routing, neural network design.

Practice questions

  1. What is a chromosome in a GA?
  2. What is the purpose of mutation?
  3. How is roulette-wheel selection probability computed?

Answers to the practice questions

  1. A coded representation of a candidate solution, often a bit string.
  2. To introduce random variation and maintain diversity.
  3. Fitness of the individual divided by the total fitness.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit II