HomeArticlesBiology & Life

Genetic Algorithms: Optimisation by Simulated Natural Selection

Selection, crossover and mutation, applied to a population of digital genomes, can climb a fitness landscape too rugged for calculus-based optimisation to handle.

mysimulator teamUpdated June 2026≈ 8 min read▶ Open the simulation

Search by imitating selection, not by imitating biology exactly

A genetic algorithm (GA) treats a hard optimisation problem the way natural selection treats a population: keep a pool of candidate solutions (a "population" of "chromosomes", often just an array of numbers or bits encoding a design), score each one with a fitness function that measures how good it is, and repeatedly build a new generation by preferring the fitter parents, mixing their genes, and occasionally mutating. John Holland formalised the approach in the 1970s specifically as a way to study adaptation computationally, and the algorithm has since become a standard, general-purpose tool wherever the search space is too large or too irregular for calculus-based optimisation.

1. initialise a random population of N candidate solutions
2. evaluate fitness(individual) for every member
3. select parents, biased toward higher fitness
4. crossover: combine pairs of parents into offspring
5. mutate offspring with small probability
6. replace the population with the new generation
7. repeat from step 2 until fitness stops improving (or a target is reached)
live demo · population fitness climbing across generations● LIVE

Selection: choosing who reproduces

Tournament selection is the most widely used method in practice: pick k individuals at random from the population and let the fittest of those k become a parent, repeated as many times as parents are needed. It is cheap, does not require sorting the whole population, and the tournament size k directly controls selection pressure — k = 1 is pure random choice (no pressure at all), while a large k approaches always picking the single best individual, which converges fast but risks losing genetic diversity too early. Roulette-wheel (fitness-proportionate) selection is the classical alternative, giving each individual a chance of being picked proportional to its fitness score, though it is sensitive to fitness scaling — one dominant individual can crowd out the rest of the population within a few generations unless fitness values are normalised first.

Crossover: combining, not just copying

Crossover recombines two parent genomes into offspring, and this recombination — not mutation alone — is what lets a GA discover combinations of good sub-solutions that neither parent had individually. Single-point crossover picks one cut position and swaps everything after it between the two parents; two-point and uniform crossover swap more finely, with uniform crossover choosing each gene independently from one parent or the other. Which scheme works best depends on whether nearby genes in the encoding tend to interact — a property called linkage — which is exactly why choosing a good representation for the problem (how a candidate solution is encoded as a chromosome) is often the single most important design decision in applying a GA at all.

parent A:  1 0 1 1 | 0 0 1
parent B:  0 1 0 0 | 1 1 0
                    ^ crossover point

child:     1 0 1 1 | 1 1 0     (tail swapped from parent B)

Mutation: the source of genes that were never in the population

Selection and crossover can only ever recombine genetic material already present in the population; mutation — flipping a bit, nudging a real-valued gene, or swapping two elements — is the only operator that introduces genuinely new values, and it is what prevents the search from getting permanently stuck once the population has converged around one region of the search space. Mutation rate is a delicate knob: too low and the population can prematurely converge to a mediocre local optimum with no way back out (a failure mode called genetic drift when it happens by chance rather than by selection pressure); too high and the algorithm degrades toward pure random search, destroying good building blocks faster than selection can favour them.

The fitness landscape, and why GAs are good at rugged ones

Picture every possible genome as a point in a high-dimensional space, with fitness plotted as a height above it — the fitness landscape. Gradient-based optimisers climb the nearest local peak efficiently but get stuck there permanently if the landscape is rugged, with many separated peaks of different heights. A GA's population is spread across many points at once and its selection pressure is soft rather than absolute, so weaker-but-different individuals survive long enough to sometimes cross a valley and discover a taller peak elsewhere — a property called exploration versus exploitation balance. This is precisely why GAs are reached for on problems like circuit layout, scheduling, neural architecture search and evolvable game-playing strategies, where the fitness landscape is known to be irregular and a single smooth gradient to follow does not exist.

Frequently asked questions

How is a genetic algorithm different from just trying random solutions?

Pure random search never remembers what worked. A GA keeps a population, deliberately combines the genes of its fitter members through crossover, and only mutates on top of that — so useful partial solutions (building blocks) that appear anywhere in the population tend to survive and recombine into better ones, rather than every attempt starting from scratch.

What happens if the mutation rate is set too high or too low?

Too low, and the population can converge prematurely to a mediocre solution with no mechanism left to escape it. Too high, and mutation destroys good combinations faster than selection can reward them, and the algorithm degrades toward undirected random search.

Why does tournament size matter for selection?

Tournament size controls selection pressure. A small tournament (even just 2 competitors) keeps the population diverse because weaker individuals still have a real chance to become parents; a large tournament pushes strongly toward always picking near-best individuals, which speeds convergence but risks losing the diversity needed to escape a local optimum.

Try it live

Everything above runs in your browser — open Genetic Evolution and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Genetic Evolution simulation

What did you find?

Add reproduction steps (optional)