The main processing loop alternates between updating the ant trails based on the current pheromone values and updating the pheromones based on the new ant trails.After the maximum number of times (1,000) through the main processing loop, the program displays the best trail found and its corresponding length (61.0 units).The 60-city graph is artificially constructed so that every city is connected to every other city, and the distance between any two cities is a random value between 1.0 and 8.0 arbitrary units (miles, km and so forth). With 60 cities, assuming you can start at any city and go either forward or backward, and that all cities are connected, there are a total of (60 - 1)!

travelling salesman problem ant system algorithm pheromone updating-10

In this month’s column I present C# code that implements an Ant Colony Optimization (ACO) algorithm to solve the Traveling Salesman Problem (TSP).

An ACO algorithm is an artificial intelligence technique based on the pheromone-laying behavior of ants; it can be used to find solutions to exceedingly complex problems that seek the optimal path through a graph.

The best way to see where I’m headed is to take a look at the screenshot in Figure 1.

In this case, the demo is solving an instance of the TSP with the goal of finding the shortest path that visits each of 60 cities exactly once.

ACO is a meta-heuristic, meaning that it’s a general framework that can be used to create a specific algorithm to solve a specific graph path problem. Since then, ACO has been widely studied and modified, but, somewhat curiously, very few complete and correct implementations are available online.

Although ACO was proposed in a 1991 doctoral thesis by M. This column assumes you have intermediate-to-advanced programming skills.

Dorigo, the first detailed description of the algorithm is generally attributed to a 1996 follow-up paper by M. I implement the ACO program using C#, but you shouldn’t have too much trouble refactoring my code to a different language, such as Java Script.

The demo program uses four ants; each ant represents a potential solution.

ACO requires the specification of several parameters such as the pheromone influence factor (alpha) and the pheromone evaporation coefficient (rho), which I’ll explain later.