Genetic Algorithm Simulator (Watch Predator–Prey Evolution and Visualize Every Genome)
Completely free, with no extra charges. You may freely use the output commercially.
About this tool
This simulator lets you watch how the “selection, crossover and mutation” of a genetic algorithm (GA) actually work, in a small world where herbivores graze on grass and carnivores hunt the herbivores. Every animal carries a genome (a bit string) made of several 8-bit genes, and only those that survive and build up enough energy get to have offspring. Over the generations, body colors that blend into the background and running speeds that pay for their own energy cost are selected naturally.
Just press the play button to start. Change the mutation rate or the background color while it runs and you can watch the population's genomes reorganize. Click an animal in the field to see its bit string, where its parents' genomes were crossed over and which bits mutated. All processing happens entirely in your browser (no data is sent).
How it works and how to read the screen are explained in the article “Watching a Genetic Algorithm in a Predator–Prey Ecosystem”.
Ecosystem
- Elapsed
- 0 steps
- Herbivores
- 0 (up to generation 0)
- Carnivores
- 0 (up to generation 0)
Circles are herbivores, and the brightness of each fill is the value of its “body color” gene. Triangles are carnivores. The depth of green on the ground shows how much grass is left. Click an animal to see its genome.
Controls (adjustable while running)
Advanced settings (used when you press “Restart”)
Selected animal's genome
Click an animal in the field or pick one with the buttons above, and its genome appears here.
Population genomes
Each row is one animal's genome and each cell is one bit (dark = 1, light = 0). Rows are sorted so that similar genomes sit next to each other. The strip at the very top shows the share of the whole population that has a 1 in that bit. The more the vertical stripes line up, the more that gene has spread through (converged in) the population.
Population and gene trends
HerbivoresCarnivores
Gene averages (band shows population spread, ±1 standard deviation)
The vertical axis is each gene's 8 bits converted to a value from 0 to 1. The dotted line on the body color chart is the background brightness at that moment.
How to use
- Press “▶ Play”. The genomes start out random, so body colors and speeds are all over the place.
- Watch for a while (1–2 minutes at ×12). The herbivores' body color moves toward the background and the vertical stripes in “Population genomes” line up. In the population chart you will see waves: carnivores increase after herbivores increase, and fall when herbivores fall.
- Move “Background brightness” to the opposite side. The animals that now stand out get eaten first, and the average body color shifts toward the new background.
- Set the mutation rate to 0% before changing the background, and the population can only use the bit combinations it still has, so adaptation may stall partway. Raise it to 8% and the stripes that had lined up fall apart.
- Click an animal to see its bit string, the value of each gene, the crossover point (┃) where it inherited from its parents and the mutated bits (★).
How genetic algorithm terms map to this simulator
| GA term | In this simulator |
|---|---|
| Individual / chromosome | One animal and its genome (48 bits for herbivores, 32 bits for carnivores) |
| Gene encoding | An 8-bit binary number is read as an integer from 0 to 255 and mapped onto each gene's range (e.g. speed 0.5–2.0) |
| Fitness | Not given by a formula. Animals that eat, escape and push their energy past their “breeding threshold” have offspring |
| Selection | Animals that are easy to spot or burn too much energy get eaten or starve before they can reproduce |
| Crossover | One-point crossover with a nearby animal of the same species. The part before the cut comes from itself, the part after from the partner |
| Mutation | Each bit of the offspring's genome is flipped with the set probability |
| Generation | No wholesale replacement. Offspring get their parent's generation number +1, and parents and offspring live side by side |
What each gene does and what it costs
- Speed: faster animals escape or catch up more easily, but the energy needed to maintain the body grows with the square of the speed.
- Vision: lets an animal notice grass, enemies or prey from farther away, at a slightly higher energy cost.
- Body color (herbivores): the closer it is to the background brightness, the shorter the distance at which carnivores notice the animal (down to 30% of their vision).
- Timidity (herbivores): how close within its vision an enemy may come before the animal flees. Too timid, and it has less time to eat.
- Flocking (herbivores): how strongly it moves toward its peers. A group makes it harder for carnivores to pick a target (the confusion effect), but members compete for grass.
- Lurking (carnivores): how much it waits instead of roaming when no prey is in sight. Staying still saves energy but makes encounters with prey rarer.
- Breeding threshold: the animal gives birth when its energy exceeds this value. A low threshold means many offspring early; a high one means slower breeding but more energy passed to each offspring.
The numbers and rules here form a simplified model meant to make the behavior of a genetic algorithm easy to see. They do not reproduce the ecology of real animals.