This simulation needs WebAssembly, and it could not start in this browser.
The image is a frame from a real run. Check that JavaScript is on, or try another browser.
Ants find food without a map. A foraging ant lays a chemical trail, other ants follow the trail and reinforce it, and the colony settles on routes that no single ant planned. Pierre-Paul Grassé called this kind of coordination through a shared environment stigmergy (1959), from his work on termites. Simon Goss, Jean-Louis Deneubourg and colleagues showed it in the laboratory in 1989: Argentine ants offered two bridges of different length to a food source end up on the shorter one, because its trail is refreshed more often. Marco Dorigo turned the idea into an optimization method in his 1992 thesis, the start of ant colony optimization.
This simulation is an agent model of that mechanism, with two pheromone fields: one that leads to food and one that leads home.
What you see
An 800 by 800 pixel arena with walls that the ants bounce off. The orange disc in the center is the nest, the three green discs are food sources that never run out. Grey ants are searching, gold ants carry a green crumb of food, and red ants are running from the predator. The teal haze is the home trail, the amber haze the food trail; turning off Show pheromones hides both. The line at the bottom counts searching, carrying and fleeing ants.
All ants start at the nest with random headings. The first ant reaches food after about 70 steps and the first crumb is home after about 140 steps (one step per frame, so about 2 seconds at 60 frames per second). Within the first minute, ants that found food lay amber trails back to the nest, others follow them out, and deliveries climb to several hundred per minute. Trails are not permanent: a route that loses its traffic evaporates, ants that stray from it get lost for a while, and new trails form, so the delivery rate rises and falls by a factor of two or more over a few minutes.
Rule
Each step, both pheromone fields on the grid evaporate and diffuse,
with the Evaporation (per step) and (at most 0.18) for the Diffusion . No pheromone leaves through the walls, and each cell holds at most 1.
Then every ant moves once:
- A searching ant smells the food trail, a carrying ant the home trail. It samples the field at three points, straight ahead and 45° to either side, at the Sensor distance (pixels).
- If the three samples together are below 0.003, it turns by a random angle of up to radians, with the Wander (at least 0.15). Otherwise it turns towards the stronger side sample, by up to about 0.28 radians, or keeps roughly its heading if the middle one is strongest.
- It walks 4 pixels times the Walking speed.
- A searching ant within 14 pixels of a food source picks up food, a carrying ant within 22 pixels of the nest drops it, and both turn around.
- It adds pheromone to the cell under it, searching ants to the home trail and carrying ants to the food trail. The amount is
with the Pheromone deposit and the number of steps since the ant last left the nest or a food source. Each trail is therefore strongest near its source, which is what lets ants follow it in the right direction. With a constant deposit the trails carry no direction, and the colony brings home less food than with no trails at all.
Presets
Numbers are from five-minute runs (18000 steps).
Default colony: 80 ants and the default values. About 2100 crumbs reach the nest, about 5 per ant per minute. The same colony with the evaporation at its maximum of 0.12, where trails vanish within a few steps, brings home about 300.
Large colony: 300 ants. About 6400 crumbs reach the nest, about 4 per ant per minute, so more ants bring more food but each one is a little less efficient.
Fast evaporation: evaporation 0.06, so pheromone lasts about 17 steps and a trail reaches only about 70 pixels behind the ant that lays it, while the food sources are 285 to 340 pixels from the nest. Only about 400 crumbs reach the nest, one per ant per minute.
Parameters
Colony size (ants): 5 to 300 (default 80).
Walking speed: 0.2 to 3 times the base speed of 4 pixels per step (default 1).
Sensor distance (pixels): 15 to 130 (default 50).
Wander: 0 to 1 (default 0.3). Even at 0, an ant with no trail to follow keeps turning a little.
Pheromone deposit: the factor above, 0.1 to 3 (default 1).
These five apply on Reset.
Evaporation (per step): 0.001 to 0.12 (default 0.012, a lifetime of about 80 steps). Diffusion: 0 to 0.5 (default 0.08). Both apply immediately.
Grid resolution (cells per side): 30 to 200 (default 100). Changing it restarts the colony. A coarse grid gives wider trails, a fine one narrower ones; the deliveries barely change (about 2000 to 2400 in five minutes at 50, 100 and 200).
Predator: makes the pointer a predator while it is over the canvas. Ants closer than the Flee radius (pixels) (default 100) run straight away from it at 1.4 times their speed until they are 1.6 times that distance away, then carry on with what they were doing, food included. A predator held on the nest stops all deliveries.