Genetic Algorithms: Evolution in Code
Selection, crossover and mutation: watch a population of bit strings evolve towards a perfect solution, generation by generation.
📄 Illustrated notes · every chapter as a picture · printable
Quick quiz
3 questions to check your understanding.
Go deeper
University-level written lectures in The AI Lecture Hall:
Transcript
Introduction. Nature solves hard design problems through evolution. Genetic algorithms borrow that idea: breed better and better solutions over many generations.
The loop. Start with a population of random candidate solutions. Score each one with a fitness function. Select the fitter ones as parents. Combine their genes with crossover. Add small random mutations. Then repeat.
Watching evolution. Here each individual is a string of sixteen bits, and fitness simply counts the ones. Green cells are ones. Watch generation by generation as selection, crossover and mutation push the population towards all ones. The chart on the right tracks the best fitness, and by generation sixteen it finds the perfect string of sixteen ones.
The operators. Crossover combines good pieces from two parents into one child. Mutation randomly flips a bit now and then. Crossover exploits what already works. Mutation keeps exploring.
Applications. Genetic algorithms are useful when the search space is huge and there is no neat formula. Timetables, engineering designs, tuning other algorithms, and even evolving game strategies.
Recap. To recap. A population evolves. Fitness decides who reproduces. Crossover mixes good ideas and mutation explores new ones. Great for big, messy search problems.