Genetic Algorithm with Island Model
The method of solving optimization problems by letting bad solutions go extinct.
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.
Global Elite Pool
The elite pool is empty. Start the evolution to fill it with the best individuals from each island.
Island Populations
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.
Definition
What are Evolutionary Algorithms?
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
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: On their own, the islands evolve in isolation and keep their own approaches; their best individuals meet only in the elite pool. Only “Force Migration” swaps the best individuals between neighboring islands, once per click.
- 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.
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.
Check
Quiz: Understanding Evolutionary Algorithms
What is the main principle of evolutionary algorithms?
Select one answer
1. What is the main principle of evolutionary algorithms?
2. What happens during selection in evolutionary algorithms?
3. What is the main advantage of the island model?
4. What role does mutation play in an evolutionary algorithm?
5. What happens to an island during a "catastrophe" in this demo?