BONABEAU APPS

Ant Colony Optimization on the Traveling Salesman Problem

Artificial ants build tours, lay pheromone in proportion to tour quality, and let trails evaporate. Watch the amber trails thicken on the edges of good tours. The teal line is the best tour found so far.

Iteration
0
Best tour length
–
This iteration's best
–
Strongest trail τ
–
Pheromone trail (thicker = more) Best tour so far City (click the map to add one while paused) Ant

How one iteration works

1. Each ant builds a tour

An ant in city i picks the next unvisited city j with a probability that rises with the pheromone τij on that edge and with the heuristic desirability ηij = 1 / dij, the inverse distance:

pij = [τij]α · [ηij]β  /  Σl unvisited [τil]α · [ηil]β

A visited list keeps each city from appearing twice, so every ant ends with a valid closed tour.

2. Trails evaporate

Before any new deposit, every edge loses a fraction ρ of its pheromone. Early tours are nearly random, so forgetting them is what lets the colony move toward better solutions instead of locking in its first guesses:

τij ← (1 − ρ) · τij

The same mechanism lets real ant colonies escape a long branch once a shorter one appears, something the biological experiment shows they cannot do when pheromone decays too slowly.

3. Ants deposit pheromone

Each ant k with a tour of length Lk adds pheromone to every edge it crossed. Shorter tours deposit more, so edges shared by many short tours accumulate the most:

Δτijk = Q / Lk   if edge (i, j) is in the tour, else 0

This is the stigmergic variable: ants never talk to each other, they only read and write the environment. The optional daemon action is a centralized step from the broader ACO metaheuristic that reinforces the best-so-far tour on top of the ants' deposits.

Things to try

Set β to 0 and watch the colony converge on one mediocre tour: pure pheromone amplification stagnates. Set α to 0 and the trails never matter; you get repeated greedy walks. Push ρ near 1 and the colony has no memory, so it barely improves. Add a city mid-run (pause first) and watch the trails reroute around it.

Ant System finds short tours, not provably shortest ones. For a problem this size a near-optimal answer in a few dozen iterations is the point.