6 Swarm intelligence: Ants
Swarm intelligence draws inspiration from collective animal behavior rather than genetic reproduction, showing how simple agents can produce sophisticated, emergent solutions. Ants exemplify this: as individuals they are limited, but as colonies they coordinate through pheromones—chemical “notes” that bias future movement—leading to efficient group outcomes such as quickly converging on the shortest path between a nest and food. Ant Colony Optimization (ACO) captures this phenomenon for difficult optimization problems with large, rugged search spaces, offering an alternative to genetic algorithms: while GAs often suit discrete selection problems, swarm approaches (including ACO and particle swarms) excel where solutions are guided by continuous or heuristic feedback.
The chapter frames ACO through a path-finding “Carnival Problem,” modeling attractions as graph nodes with a distance matrix and maintaining a parallel pheromone matrix. Ants are lightweight agents with memory (visited nodes), an action rule (choose next node and lay pheromones), and a fitness measure (tour length). The algorithm’s life cycle is consistent across domains: initialize uniform pheromones; place a population of ants at random starts; iteratively build tours by choosing the next move via a probabilistic balance of pheromone strength and a heuristic (e.g., inverse distance), weighted by alpha and beta; update trails through evaporation (to forget stale information) and depositing pheromones in proportion to tour quality; record the best tour; and repeat until stopping criteria (fixed iterations or stagnation). Roulette-wheel selection enables exploration while biasing choices toward promising edges, and key parameters—alpha, beta, evaporation rate, number of ants, iterations—govern the exploration–exploitation trade-off and runtime.
Beyond toy graphs, ACO generalizes by swapping “distance” for domain-specific heuristics and constraints. It addresses route optimization (e.g., logistics under traffic, timing, and load constraints), job scheduling (e.g., nurse rosters or compute tasks with priorities and rest rules), and even image processing (edge detection by reinforcing high-contrast pixel transitions). Compared with brute-force enumeration—which becomes intractable as graph size grows—ACO scales by leveraging collective learning, guided randomness, and pheromone memory to rapidly home in on high-quality solutions. Effective use hinges on careful encoding of the heuristic, thoughtful parameter tuning, and sufficient iterations and colony size to let good paths outcompete the rest.
A group of ants working together to cross a chasm
Asymmetric bridge experiment
Problems addressed by swarm optimization
Carnival attractions and paths between them
Distances between attractions and a possible path
Distances between attractions and an optimal path
A larger dataset of attractions and paths between them
An example of the Carnival Problem
Properties of an ant
Example pheromone intensity on paths
The ant colony optimization algorithm life cycle
Set up the pheromones.
Initialization of pheromones
Set up the population of ants.
Ants start at random attractions.
Choose the next visit for each ant.
Example of possible paths from the circus
The pheromone influence and heuristic influence of the formula
Probability calculations for paths
The final probability of each attraction being selected
Example of possible paths from the circus, excluding visited attractions
Probability calculations for paths
The final probability of each attraction being selected
Update the pheromone trails.
Example of updating pheromone trails for evaporation
Pheromone updates based on ant movements
Update the best solution.
Reached stopping condition?
Parameters that can be tweaked in the ant colony optimization algorithm
Grokking AI Algorithms, Second Edition ebook for free