Genetic Algorithm Visualizer — Evolution, Selection & Fitness

Watch populations evolve through selection, crossover, and mutation — six modes from function optimisation to TSP

0
Generation
Best Fitness
Avg Fitness
Diversity

Preset

Parameters

Population40
Mutation rate2%
Crossover rate80%
Elitism2

Stats

0
Generation
Best
Avg
Improvement

Controls

How Genetic Algorithms Work

Selection

Tournament selection picks k random individuals and keeps the fittest. Roulette-wheel selection (fitness-proportionate) gives each individual a probability proportional to fitness. Both create selection pressure the force driving the population toward high-fitness regions.

Crossover (Recombination)

One-point crossover splits parents at a random locus and swaps the tails. Two-point uses two loci. Uniform crossover independently picks each gene from either parent with probability 0.5. For permutation problems like TSP, ordered crossover (OX) preserves relative ordering of cities.

Mutation

Bit-flip mutation independently flips each bit with probability p_m 1/L (chromosome length). Real-valued GAs add Gaussian noise s to each gene. Mutation prevents premature convergencewithout it the population loses diversity and may get stuck in local optima.

Elitism & Diversity

Elitism copies the best e individuals unchanged to the next generation, guaranteeing the best solution is never lost. Without elitism, good solutions can be destroyed by crossover or mutation. Diversity metrics (average Hamming distance, entropy) track whether the population is converging or still exploring.

Applications by Domain

DomainProblemChromosomeFitness
LogisticsVehicle routing, TSPPermutation1/tour length
Engineering designStructural topology, aerodynamic shapesReal-valued vectorStress / drag minimisation
Machine learningNeural architecture search, hyperparameter tuningInteger / mixedValidation accuracy
BioinformaticsProtein folding, sequence alignmentAmino acid stringEnergy / alignment score
SchedulingJob-shop, timetabling, resource allocationPermutationMakespan, conflicts
FinancePortfolio optimisation, trading rulesBinary / realSharpe ratio
Game AIEvolving game-playing agents, level generationStrategy treeWin rate
VLSI designCircuit layout, cell placementPermutationWire length, timing

Variants & Extensions

VariantKey IdeaBest Used For
Simple GA (SGA)Binary chromosomes, roulette selection, one-point crossoverBenchmark problems
Real-coded GAFloating-point chromosomes, BLX-a crossover, Gaussian mutationContinuous optimisation
NSGA-IINon-dominated sorting + crowding distance for multi-objectivePareto front problems
CMA-ESCovariance matrix adaptation learns correlations between variablesHigh-dim continuous
Island Model (parallel GA)Multiple sub-populations periodically exchange migrantsDiversity, large scale
Genetic ProgrammingChromosomes are programs (syntax trees)Symbolic regression

Explore Genetic Algorithms in Depth

Read the complete guide to evolutionary algorithms selection pressure, fitness landscapes, convergence analysis, and real-world applications.

Read: Evolutionary Algorithms Guide →

Frequently Asked Questions

How does a genetic algorithm work?

A GA maintains a population of candidate solutions. Each generation: evaluate fitness; select parents (fitter individuals more likely); produce offspring via crossover; apply mutation. Elitism copies the best unchanged. Over hundreds of generations, average fitness rises as good building blocks spread through the population via Holland's implicit parallelism.

What is Holland's Schema Theorem?

Short, low-order schemata (bit templates) with above-average fitness receive exponentially increasing representation in successive generations. Despite evaluating only N individuals, the GA implicitly processes O(N) schemata the building-block hypothesis. This explains why GAs efficiently search enormous spaces by assembling sub-patterns rather than individual solutions.

What is the difference between crossover and mutation?

Crossover combines two parents to create offspring mixing genetic material. It is the primary driver of exploration and exploitation. Mutation independently perturbs each gene at a low rate (p_m 1/L), preventing premature convergence by maintaining diversity and injecting novelty. Too-high mutation rate turns the GA into random search; too-low loses diversity.

Why does a GA struggle with deceptive functions?

Deceptive functions mislead selection: short, individually-fit sub-patterns combine to give poor fitness, while the true global optimum requires individually-poor sub-patterns. Standard GAs converge to the deceptive attractor. Solutions include niching, fitness sharing, island models, or switching to estimation-of-distribution algorithms that model the full solution distribution rather than individual genes.