The Core Principles
At its heart, a genetic algorithm operates on a population of potential solutions to a problem. Each solution is represented as an ‘individual’ or ‘chromosome,’ typically encoded as a string of bits (binary representation) or numbers.
These chromosomes are then subjected to processes analogous to natural selection: reproduction (crossover), mutation, and selection. The fittest individuals – those with the best solutions – are more likely to reproduce and pass on their characteristics.
Crossover & Mutation
Crossover simulates sexual reproduction, combining genetic material from two parent chromosomes to create offspring. This introduces new combinations of traits into the population.
Mutation randomly alters a chromosome’s code, introducing diversity and preventing premature convergence on local optima. The mutation rate is crucial; too high, and solutions become unstable; too low, and exploration stagnates.
P_crossover = α * (chromosome1 ∩ chromosome2) + (1 - α) * chromosome1 (α: crossover probability)
Selection Methods
Various selection methods determine which individuals contribute to the next generation. Common techniques include Roulette Wheel Selection (probability proportional to fitness), Tournament Selection, and Rank-Based Selection.
Roulette wheel selection assigns probabilities based on an individual's ‘fitness’ – how well it solves the problem. Tournament selection randomly selects a subset of individuals and chooses the fittest from that group.
Applications & Considerations
Genetic algorithms excel in problems with complex, non-linear landscapes where gradient-based methods struggle. Examples include route optimization (Traveling Salesman Problem), scheduling tasks, and parameter tuning.
The efficiency of a genetic algorithm depends heavily on parameters like population size, crossover rate, mutation rate, and the selection method used. Careful tuning is essential for optimal performance.
Frequently asked questions
What makes Genetic Algorithms different from Gradient Descent?
Gradient descent relies on calculating derivatives to find the minimum of a function, which can be difficult for complex, non-differentiable problems. GAs use a population-based approach mimicking evolution.
How do I define ‘fitness’ in a Genetic Algorithm?
'Fitness' is a measure of how well an individual solution performs on the problem being solved. It’s typically defined based on the objective function you want to minimize or maximize.
Can Genetic Algorithms always find the optimal solution?
No, GAs are stochastic (random) methods and don't guarantee finding the absolute best solution. However, they often converge to a near-optimal solution within a reasonable timeframe.
Try it live
Everything above runs in your browser — open SPH Fluid and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open SPH Fluid simulation