Genetic Algorithm & Evolution
Comprehensive notes, formulas, and practice questions for Genetic Algorithm & Evolution.
What you'll learn
- How genetic algorithms are inspired by natural selection
- Key vocabulary: chromosome, gene, fitness function
- The three genetic operators: selection, crossover, mutation
- How populations evolve over generations
- Real-world applications of genetic algorithms
- How genetic algorithms compare to gradient descent
Key concepts
Inspiration: Natural Selection
Charles Darwin observed that organisms with traits better suited to their environment survive and reproduce more. Over generations, beneficial traits become more common.
Genetic algorithms (GAs) apply this principle to optimisation problems: evolve a population of candidate solutions toward better and better answers.
Key Vocabulary
| Term | Biological analogy | In a GA |
|---|---|---|
| Chromosome | An organism's DNA | One candidate solution (e.g., a binary string) |
| Gene | One segment of DNA | One variable or parameter in the solution |
| Population | Group of organisms | Set of candidate solutions in one generation |
| Fitness | Survival ability | A score measuring how good a solution is |
| Generation | One cycle of reproduction | One iteration of the GA loop |
Example: Optimising a delivery route.
- Chromosome: [3, 1, 4, 2, 5] (order of cities to visit)
- Gene: each city index
- Fitness: total route distance (lower = more fit)
The Fitness Function
The fitness function assigns a numerical score to each chromosome. It is problem-specific.
The GA does not need to know how to solve the problem — it only needs to evaluate how good each solution is.
The Three Genetic Operators
1. Selection
Choose which chromosomes reproduce. More fit solutions get a higher probability of being selected.
Common methods:
- Roulette wheel selection: probability proportional to fitness.
- Tournament selection: pick the best from a random subset.
2. Crossover (Recombination)
Two parent chromosomes exchange segments to create offspring.
| Parent 1 | 1 0 1 1 | 0 0 1 | | Parent 2 | 0 1 0 0 | 1 1 0 | | Child 1 | 1 0 1 1 | 1 1 0 | | Child 2 | 0 1 0 0 | 0 0 1 |
Single-point crossover at position 4.
This combines good traits from both parents.
3. Mutation
Randomly alter one or more genes with a small probability.
1 0 1 1 0 0 1 → 1 0 **0** 1 0 0 1 (gene 3 flipped)
Mutation maintains diversity and prevents the population from getting stuck in a local optimum.
The GA Loop (Generations)
1. Initialise: Create a random population
2. Evaluate: Score each chromosome with the fitness function
3. Select: Choose parents (higher fitness → higher probability)
4. Crossover: Create offspring by combining parents
5. Mutate: Randomly alter some genes in offspring
6. Replace: Form new generation from offspring
7. Repeat steps 2–6 until stopping criterion is met
(max generations, or fitness threshold reached)
Over many generations, the average fitness of the population increases.
Applications
| Domain | Application |
|---|---|
| Engineering | Aerodynamic shape optimisation |
| Scheduling | Job scheduling, timetabling |
| Routing | Travelling Salesman Problem, logistics |
| Machine learning | Neural network architecture search |
| Game AI | Evolving AI behaviour (e.g., game agents) |
| Biology | Protein structure prediction |
Genetic Algorithm vs Gradient Descent
| Feature | Genetic Algorithm | Gradient Descent |
|---|---|---|
| Requires gradient? | No | Yes |
| Handles discrete variables? | Yes | Hard (requires relaxation) |
| Risk of local optima | Lower (population-wide search) | Higher (single trajectory) |
| Speed | Slower (many evaluations) | Faster (direct optimisation) |
| Best for | Combinatorial, non-differentiable problems | Continuous, differentiable functions |
Quick check
-
Explain the analogy between natural selection and a genetic algorithm. What corresponds to "survival of the fittest" in a GA?
-
A GA is used to find the shortest delivery route through 10 cities. Define what the chromosome, gene, and fitness function would be for this problem.
-
After crossover, two offspring are created. Why is mutation also applied, even though the offspring already combine traits from two fit parents?
-
A GA population converges to the same chromosome after 50 generations, but it is not the global optimum. What problem has occurred, and how can it be prevented?
-
A problem has a fitness landscape with many local optima and a discontinuous (non-differentiable) objective function. Why is a genetic algorithm better suited here than gradient descent?
Key Takeaways (TL;DR)
- What you'll learn
- Key concepts
- Quick check
Master this topic with Drishti OS
Get unlimited mock tests, AI-powered mentorship, and complete video courses when you join.
Start Free Practice