Path: blob/main/notebooks/published/ant_colony_optimization/ant_colony_optimization.ipynb
51 views
Ant Colony Optimization (ACO)
Introduction
Ant Colony Optimization (ACO) is a probabilistic technique for solving computational problems that can be reduced to finding good paths through graphs. This metaheuristic algorithm was introduced by Marco Dorigo in 1992, inspired by the foraging behavior of real ants.
Biological Inspiration
In nature, ants initially wander randomly. Upon finding food, they return to their colony while laying down pheromone trails. Other ants follow these trails, and if they find food, they reinforce the trails with more pheromones. Over time, shorter paths accumulate more pheromones (since ants can traverse them more quickly), leading to the emergence of optimal routes.
Mathematical Formulation
Transition Probability
The probability that ant at node will move to node is given by:
where:
is the pheromone intensity on edge
is the heuristic desirability (inverse of distance)
is the pheromone influence parameter
is the heuristic influence parameter
is the set of feasible nodes for ant at node
Pheromone Update Rule
After all ants complete their tours, the pheromone levels are updated according to:
where:
is the pheromone evaporation rate
is the number of ants
is the pheromone deposited by ant
Pheromone Deposit
The amount of pheromone deposited by ant on edge is:
where:
is a constant
is the total length of the tour constructed by ant
Application: Traveling Salesman Problem (TSP)
We will demonstrate ACO on the classic Traveling Salesman Problem, where the goal is to find the shortest possible route that visits each city exactly once and returns to the origin city.
Generate Test Data
We will create a set of randomly distributed cities in a 2D plane and compute the Euclidean distance matrix.
Run ACO Algorithm
Visualization
Let's visualize the results: the convergence history, the pheromone intensity matrix, and the optimal tour found by the algorithm.
Analysis and Results
The visualization above shows:
Convergence Plot: The algorithm rapidly improves in early iterations and then converges to a stable solution. The gap between mean and best distances indicates the exploration-exploitation balance.
Pheromone Matrix: Brighter cells indicate stronger pheromone trails between cities. The diagonal is zero (no self-loops).
Best Tour: The optimal route found by the algorithm, connecting all cities with minimal total distance.
Pheromone Trails: Visual representation of the learned solution structure. Stronger trails (thicker, more opaque lines) indicate preferred connections.
Key Observations
Parameter Sensitivity: The balance between (pheromone influence) and (heuristic influence) is crucial. Higher values lead to more greedy behavior, while higher values emphasize learned information.
Evaporation Rate: The parameter controls how quickly old information is forgotten. Too high evaporation leads to loss of good solutions; too low leads to premature convergence.
Swarm Intelligence: No single ant finds the optimal solution. Instead, the collective behavior of the colony, mediated through pheromone communication, gradually uncovers good solutions.
Conclusion
Ant Colony Optimization demonstrates how simple local rules can lead to complex global optimization behavior. The algorithm's strength lies in its:
Positive feedback: Good solutions are reinforced through pheromone deposits
Negative feedback: Evaporation allows the system to forget poor solutions
Stochastic exploration: Random elements prevent premature convergence
Distributed computation: Multiple ants work independently, making the algorithm naturally parallelizable
ACO has been successfully applied to various combinatorial optimization problems including vehicle routing, scheduling, network optimization, and protein folding.