Genetic Algorithm with Island Model

The method of solving optimization problems by letting bad solutions go extinct.

What are Evolutionary Algorithms?

AnalogyDefinition

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

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

The image that evolution should approach. Shows the selected reference image.

Global Best

The best evolved image of the current evolution Shows the best result from the last evolution
Best fitnessMigrationCatastrophe

Control area for evolution

EvolutionDuelSettingsStatisticsBenchmark

Evolution

Main controls for the evolution process
Main control for starting, pausing, or executing single evolution steps
0
Generation
1 / 200
Circles
0.0%
Similarity
25
Next Migration
0.00
Avg Diversity
0
Gen/Sec

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

TheoryPseudo-CodeStep by StepFlow Diagram

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.

Quiz: Understanding Evolutionary Algorithms

Question 1 / 5
Not completed

What is the main principle of evolutionary algorithms?

Select one answer
Answer Key: 1) B · 2) A · 3) C · 4) B · 5) C