Genetic Algorithm with Island Model
The method of solving optimization problems by letting bad solutions go extinct.
What are Evolutionary Algorithms?
Imagine you're breeding the perfect tomato variety for your garden. You start with different types and select the best ones each year.
Just as nature optimizes living beings over generations, evolutionary algorithms use similar principles to solve problems:
The best solutions are selected for 'breeding'
Through crossover, new combinations emerge
Small mutations bring surprising improvements
Analogy:
Imagine you're breeding the perfect tomato variety for your garden. You start with different types and select the best ones each year.
Just as nature optimizes living beings over generations, evolutionary algorithms use similar principles to solve problems:
The best solutions are selected for 'breeding'
Through crossover, new combinations emerge
Small mutations bring surprising improvements
Definition:
Evolutionary algorithms are stochastic, population-based metaheuristics for optimization. They mimic principles of biological evolution and often find very good solutions, but do not guarantee a global optimum:
Population: A set of candidate solutions for the optimization problem
Fitness Function: Evaluates the quality of each solution
Selection: Choosing the best individuals for reproduction
Genetic Operators: Crossover (recombination) and mutation create variation
How the Demo Works
Overview
This interactive demo simulates evolutionary optimization using the island model. It evolves artwork from colored circles that should resemble a target image.
Key Concepts
- Generation:A generation corresponds to one evolution cycle. In each generation, new solutions are created through selection, crossover, and mutation.
- Fitness:Fitness measures image quality as an error metric: it calculates pixel difference to the target image. Lower values = better match (0 = perfect match). Note: In classical evolution, higher fitness is better; here we use an inverted error metric.
- Islands:Separate subpopulations that evolve in parallel. Each island can have different parameters and specializes in different solution approaches.
- Elite Pool:Collection of the best individuals from all islands. These are used for special crossover operations.
- Migration:Occasional exchange of the best individuals between neighboring islands to maintain genetic diversity.
- Catastrophe:Drastic reduction of an island's population during stagnation. Only the best 20% survive, the rest is regenerated.
- Diversity:Measure of genetic variety in the population. Higher diversity prevents premature convergence to suboptimal solutions.
Interaction
Experiment with different target images, adjust parameters, observe evolution in real-time, and use the benchmark feature to compare different algorithm variants.
Performance Optimizations
- Fitness Cache:Stores previously calculated fitness values to avoid redundant computations. Since fitness calculation (pixel-by-pixel image comparison) is computationally intensive, caching dramatically improves performance when the same individual is evaluated multiple times.
- Adaptive Parameters:Automatically adjusts mutation and crossover rates based on current evolution progress. When diversity is low, mutation rate increases to explore new solutions. When converging on a good solution, crossover rate increases for refinement.
- Batch Rendering:Groups multiple canvas drawing operations to reduce browser redraws. Instead of updating after each change, updates are collected and rendered in batches, significantly improving animation smoothness.
Interactive Evolution
How circles turn into a picture
This demo repaints a picture — not with a brush, but by rearranging hundreds of translucent circles until the result resembles the target image. Here is what you see on screen.
- What you see
- Two pictures above each other: on top the target image as a template, below it the picture the evolution is currently assembling. That lower picture is made of many coloured, semi-transparent circles that overlap. At first it is just a rough blob of colour; step by step it turns into a recognisable copy of the template.
- What happens
- Over many generations the demo keeps the best candidates and changes them slightly — moving, recolouring or swapping individual circles. If a change matches the template better, it stays; so the lower picture grows more and more similar to the template. A small curve below tracks this progress.
- What you can do
- Pick a target image or upload your own, start and pause the evolution, or step through it one generation at a time. In the settings you can change the number of circles, and in the duel two strategies evolve side by side against each other.
- What to watch for
- No single circle knows what the target looks like. The recognisable picture emerges purely from keeping the best random attempts and varying them again and again — generation after generation.
Girl with Pearl Earring - Johannes Vermeer
Global Best
Control area for evolution
Evolution
Main controls for the evolution process
Duel
Pit two strategies head-to-head. Pick a preset for side A and side B and watch over 200 generations which strategy gets closer to the target image.
Settings
Advanced Controls
Algorithm Features
Enable various optimizations and observe their impact on performance.
No data yet - start evolution to see learning statistics
Automated A/B Tests
This automated benchmark runs multiple evolution tests with different feature combinations to find the optimal configuration. It compares performance metrics like generations per second, convergence rate, and final fitness values.
- 7 automatic test runs with different feature combinations
- 500 generations per test run for meaningful results
- Testing: Fitness Cache, Adaptive Parameters, Batch Rendering
Global Elite Pool
The elite pool is empty. Start the evolution to fill it with the best individuals from each island.
Island Populations
Evolutionary Algorithms Explained
Biological Evolution as Model
Evolutionary algorithms are inspired by biological evolution: They generate solutions, select the best ones, combine them, and introduce random changes. Over many generations, better and better solutions emerge.
The algorithm works with a population of solution candidates. Each generation goes through three phases: Selection (the best survive), Crossover (combining solutions) and Mutation (random changes). These operations mimic natural selection, reproduction and genetic variation.
Advantages of Evolutionary Optimization
- Global optimization: Finds good solutions even in complex search spaces with many local optima
- No gradients needed: Works for non-differentiable or discrete problems
- Parallelizable: Multiple solutions can be evaluated simultaneously
- Flexible: Can be adapted to different problem types
Challenges
Evolutionary algorithms require many evaluations of the fitness function, which can be computationally intensive. Choosing the right parameters (population size, mutation and crossover rates) is crucial for performance. There is also no guarantee of finding the global optimum – only good approximations.
Practical Applications
Typical applications: Route optimization (Traveling Salesman Problem), feature selection in machine learning, hyperparameter tuning, neural architecture search, production scheduling problems, and game strategy optimization.
Try the demo! Watch how the population develops better solutions over generations.
1
# Evolutionary Algorithm
2
function evolutionary_algorithm(problem):
3
# Main function: Evolutionary optimization
4
population = initialize_population(size)
5
fitness = evaluate_all(population)
6
7
while not_converged:
8
# Selection: Choose the best
9
parents = select_parents(population, fitness)
10
11
# Crossover: Combine genes
12
for each parent_pair:
13
genes_combined = crossover(parents)
14
offspring = create_offspring(genes_combined)
15
16
# Mutation: Random changes
17
for each offspring:
18
if random < mutation_rate:
19
mutate(offspring)
20
21
# Evaluate offspring
22
fitness_offspring = evaluate_all(offspring)
23
24
# Replacement: New generation
25
sort_by_fitness(population + offspring)
26
survivors = select_best(population_size)
27
population = survivors
28
29
# Check termination criteria
30
if termination_criteria_met():
31
break
32
33
return best_individual(population)
👥 Initialize Population
Create an initial population with random solutions. Each individual represents a possible solution to the problem.
population = initialize_population(size)
🎬 Initialization
Create random initial population. Each individual is a possible solution.
❤️ Selection
Choose fit individuals as parents. Survival of the fittest.
🔗 Crossover
Combine genes of parents. Create offspring with mixed characteristics.
⚡ Mutation
Random gene changes. New variations emerge.
📊 Evaluation
Calculate fitness of all individuals. Measure solution quality.
🔄 Replacement
Replace old with new generation. Keep the best.
✅ Termination
Check termination criterion. End when solution is good enough.
Quiz: Understanding Evolutionary Algorithms
What is the main principle of evolutionary algorithms?
1. What is the main principle of evolutionary algorithms?
- ☐ A) Mathematical derivation for optimization
- ☐ B) Mimicking biological evolution for problem solving
- ☐ C) Neural networks for pattern recognition
- ☐ D) Statistical analysis of large datasets
2. What happens during selection in evolutionary algorithms?
- ☐ A) The fittest individuals are selected for reproduction
- ☐ B) Random individuals are eliminated
- ☐ C) All individuals get equal chances
- ☐ D) The population is completely renewed
3. What is the main advantage of the island model?
- ☐ A) Faster convergence to a solution
- ☐ B) Less computational effort required
- ☐ C) Preservation of genetic diversity
- ☐ D) Simpler implementation
4. What role does mutation play in an evolutionary algorithm?
- ☐ A) It combines the genes of two parents into a child
- ☐ B) It introduces random changes and helps escape local optima
- ☐ C) It selects the fittest individuals for the next generation
- ☐ D) It copies the best individual unchanged into the next generation
5. What happens to an island during a "catastrophe" in this demo?
- ☐ A) The entire population of all islands is wiped out
- ☐ B) The mutation rate is permanently set to zero
- ☐ C) Only the best individuals survive, the rest are regenerated
- ☐ D) Two islands are permanently merged into one
Related Content
Article
Agents in Conflict — Game Theory
What a second rational player changes about an optimization — everything.
The Path to the Valley: Gradient Descent
How gradient descent finds the lowest point in a landscape with millions of hills — most of the time.
Graph Search — The Beginnings
Graph search: the first thing AI could actually do — and still useful today.
Heuristics & Pathfinding: From Dijkstra to A*
How A* works — and why Dijkstra gets boring without a heuristic.
The Machine's Knobs — Parameters vs. Hyperparameters
The fine line between "learned by the machine" and "guessed by you".
What Is an Algorithm?
What Euclid, IKEA instructions, and Google search have in common — all three are algorithms.
Demo
Swarm Intelligence (Boids)
See how three simple local rules give rise to the complex behavior of a bird flock.
Gradient Descent
Interactive demo to understand gradient descent: click a starting point on the loss landscape, watch the algorithm roll into the valley, and experiment with learning rate and optimizers.
Neuroevolution
Watch virtual cars learn to drive using neural networks and genetic algorithms - or take the wheel yourself and challenge the AI
Q-Learning
Interactive demonstration of the Q-Learning algorithm with an intelligent agent in the Temple of Learning
Travelling Salesman: Algorithms in Competition
Place cities, draw your own route, and pit Greedy, Simulated Annealing and a Genetic Algorithm against you.