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:
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:
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:
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.