🐜 Ant Colony
ACO pheromone pathfinding
Colony
Pheromone
Controls
Stats
Best tour
Iterations
0
Avg tour
Improvement
Stigmergy: Ants choose edges with probability proportional to τα·ηβ, where τ is pheromone and η = 1/distance. Shorter routes accumulate more pheromone before evaporation removes it — amplifying the best paths over time.

About Ant Colony Optimisation

Ant Colony Optimisation (ACO) is a probabilistic metaheuristic inspired by the foraging behaviour of real ants, introduced by Marco Dorigo in 1992. When ants search for food they initially explore at random, but they deposit a chemical signal called a pheromone on their trails. Shorter paths are traversed more frequently, so pheromone accumulates faster on them; other ants preferentially follow stronger pheromone trails, creating a positive feedback loop that converges on the shortest route. ACO has been successfully applied to the Travelling Salesman Problem, vehicle routing, network routing in telecommunications, and protein-folding optimisation.

The simulation places a set of cities (nodes) on a canvas and releases a colony of virtual ants that construct tours probabilistically, guided by both pheromone strength and the inverse of edge distance. You can adjust the number of ants, the pheromone evaporation rate (ρ), the relative importance of pheromone (α) versus distance (β), and watch how these parameters trade off convergence speed against the risk of getting stuck in a local optimum.

Frequently Asked Questions

How do ants choose which edge to take?

At each node, an ant selects the next city probabilistically using the formula Pᵢⱼ = (τᵢⱼ𝑚 ⋅ ηᵢⱼᵇ) / Σ(τ𝕪𝓂 ⋅ η𝕪𝓂), where τᵢⱼ is the pheromone level on edge (i,j), ηᵢⱼ = 1/dᵢⱼ is the heuristic (inverse distance), α controls pheromone influence, and β controls distance influence. Setting α=0 gives a greedy nearest-neighbour algorithm; setting β=0 relies entirely on accumulated pheromone without regard to distance.

What is pheromone evaporation and why is it important?

After each iteration, pheromone on all edges is reduced by a factor (1−ρ), where ρ is the evaporation rate typically between 0.01 and 0.5. Without evaporation the algorithm would lock onto the first decent solution it finds and never explore alternatives, because pheromone would only accumulate and never decrease. Evaporation acts as a forgetting mechanism that prevents premature convergence and allows the colony to adapt if conditions change — analogous to real pheromone degrading in sunlight and wind.

How does ACO compare to genetic algorithms?

Both are population-based metaheuristics that avoid getting trapped in local optima through exploration. ACO builds solutions incrementally and shares information through pheromone trails (a form of indirect communication called stigmergy), while genetic algorithms operate on complete candidate solutions and share information through crossover and mutation operators. ACO tends to perform better on path-based problems (routing, sequencing), whereas genetic algorithms are more flexible for problems with non-sequential solution structures.

What is the Travelling Salesman Problem?

The Travelling Salesman Problem (TSP) asks: given N cities, what is the shortest closed tour that visits each city exactly once and returns to the start? It is NP-hard, meaning no known polynomial-time exact algorithm exists for large N; the number of possible tours grows as (N−1)!/2. For 20 cities that is over 60 trillion tours. ACO typically finds near-optimal solutions far faster than exhaustive search, making it practical for real-world logistics problems with hundreds or thousands of cities.

What does the evaporation rate ρ control?

A high evaporation rate (ρ close to 1) means pheromone dissipates quickly, keeping all edges nearly equally attractive and encouraging broad exploration but slowing convergence. A low rate (ρ close to 0) lets pheromone accumulate for many iterations, reinforcing the best paths found early but risking stagnation. In practice, values of 0.1–0.3 tend to balance exploration and exploitation well for moderate-sized TSP instances.

What is the role of the α and β parameters?

α is the exponent that controls how strongly ants favour high-pheromone edges; β controls how strongly they favour short edges (low cost). With β=5 and α=1 (typical values from Dorigo's original paper), the heuristic distance dominates early when pheromone is uniform, giving sensible initial tours, while pheromone gradually shifts the balance. Setting α too high makes the algorithm rely too heavily on early, possibly poor, pheromone deposits.

Can ACO solve other problems besides routing?

Yes — ACO has been adapted to graph colouring, job-shop scheduling, protein structure prediction, and even continuous optimisation (ACOR). In network routing, Ant-Based Routing (ABR) sends "scout packets" that probe paths and deposit digital pheromone, dynamically rerouting traffic around congestion. Cisco has implemented variants of this idea in adaptive routing algorithms for telecommunications networks.

What is stigmergy?

Stigmergy is indirect coordination through environmental modification — agents communicate by changing the shared environment rather than by direct signalling. Ants' pheromone trails are the canonical example: each ant responds to trails left by previous ants, and its own trail influences future ants, with no central controller. Stigmergy is also seen in termite mound construction, wasp nest building, and has inspired distributed computing architectures.

What are the limitations of ACO?

ACO can suffer from stagnation, where all ants converge on a suboptimal tour and pheromone diversity collapses. It also requires careful parameter tuning (α, β, ρ, number of ants), and its convergence rate is generally slower than specialised algorithms for well-studied problems like TSP. Hybrid ACO systems that combine ant-based search with local improvement heuristics (2-opt or 3-opt moves) typically perform much better than pure ACO on large instances.

How many ants should be used?

A common rule of thumb is to use one ant per city. More ants increase solution diversity and reduce the chance of premature convergence, but also increase computation per iteration. Research has shown that for TSP, 10–50 ants often give good results on instances with up to 200 cities, while very large instances may benefit from hundreds of ants with parallel computation. The ideal number interacts with ρ: faster evaporation can compensate for fewer ants by maintaining diversity.