Applying Ant Colony Optimisation to travelling salesman problems in C#

Some results of applying a C# / WPF implementation of the ant colony optimisation algorithm to the travelling salesman problem (TSP).

My initial observation is that it finds fairly reasonable solutions within a given number of iterations, but falls short of algorithms such as two-opt, Lin-Kernighan etc.

The software is built around the Model-View-ViewModel (MVVM) architecture, thereby keeping the graphical display and data separate.

For an explanation of the ant colony algorithm see the Wikipedia page.

Edge selection

Each ant iteratively finds a path from the source node, visiting every other node until it reaches the start node again.

The intermediate solutions (node choices) are referred to as solution states.

At each iteration, each ant moves from a state x to state y, corresponding to a more complete intermediate solution. Thus, each ant k computes a set of feasible expansions to its current state in each iteration, and moves to one of these in probability.

For ant k, the probability of moving from state x to state y depends on the combination of two values:

1. the “attractiveness” of the move, as computed by some heuristic indicating the a priori desirability of that move and the trail level of the move, indicating how proficient it has been in the past to make that particular move. The trail level represents a posteriori indication of the desirability of that move. Trails are updated when all ants have completed their path, increasing or decreasing the level of trails corresponding to moves that were part of “good” or “bad” solutions, respectively.

In general, the kth ant moves from state x to state y with probability

YouTube demonstration of algorithm as follows:

Obtain the Visual Studio project from here:


Leave a Reply