Given a set of cities and the distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point.

For example, consider the following graph. A TSP tour in the graph is A —> B —> C —> D —> B —> A. The cost of the tour is 10 + 25 + 40 + 25 + 10 = 100.

TSP Tour

This post discusses the Travelling Salesman Problem using Branch and Bound.

 
The term Branch and Bound refer to all state-space search methods in which all the children of an E–node are generated before any other live node can become the E–node. E–node is the node, which is being expended. State–space tree can be expended in any method, i.e., BFS or DFS. Both start with the root node and generate other nodes. A node that has been generated and whose children are not yet been expanded is called a live-node. A node is called a dead node, which has been generated, but it cannot be expanded further. In this method, we expand the most promising node, which means the node which promises that expanding or choosing it will give us the optimal solution. So, we prepare the tree starting from the root and then expand it.

We have a cost matrix defined by:

C(i, j) = W(i, j), if there is a direct path from Ci to Cj
        = INFINITY, if there is no direct path from Ci to Cj

For example, consider the following cost matrix M,

Travelling Salesman Problem – Cost Matrix

Here,
 
C(0, 2) = 30
C(4, 0) = 16
C(1, 1) = INFINITY

Following is the state-space tree for the above TSP problem, which shows the optimal solution marked in green:

 
State–Space Tree: TSP Problem

As we can see from the above diagram, every node has a cost associated with it. When we go from the city i to city j, the cost of a node j will be the sum of the parent node i, the cost of an edge (i, j), and the lower bound of the path starting at node j.

As the root node is the first node to be expanded, it doesn’t have any parent. So, the cost will be only the lower bound of the path starting at the root.

Now, how do we calculate the lower bound of the path starting at any node?

In general, to get the lower bound of the path starting from the node, we reduce each row and column so that there must be at least one zero in each row and Column. We need to reduce the minimum value from each element in each row and column.

Let’s start from the root node.

We reduce the minimum value in each row from each element in that row. The minimum in each row of cost matrix M is marked by blue [10 2 2 3 4] below.

Travelling Salesman Problem – Step 1

After reducing the row, we get the below reduced matrix.

Travelling Salesman Problem – Step 2

We then reduce the minimum value in each column from each element in that column. Minimum in each column is marked by blue [1 0 3 0 0]. After reducing the column, we get below the reduced matrix. This matrix will be further processed by child nodes of the root node to calculate their lower bound.

Travelling Salesman Problem – Step 3

The total expected cost at the root node is the sum of all reductions.

Cost = [10 2 2 3 4] + [1 0 3 0 0] = 25

Since we have discovered the root node C0, the next node to be expanded can be any node from C1, C2, C3, C4. Whichever node has a minimum cost will be expanded further. So, we have to find out the expanding cost of each node.

The parent node C0 has below reduced matrix:

Travelling Salesman Problem – Step 4

Let’s consider an edge from 0 —> 1.

1. As we add an edge (0, 1) to our search space, set outgoing edges for city 0 to INFINITY and all incoming edges to city 1 to INFINITY. We also set (1, 0) to INFINITY.

So in a reduced matrix of the parent node, change all the elements in row 0 and column 1 and at index (1, 0) to INFINITY (marked in red).

Travelling Salesman Problem – Step 5

The resulting cost matrix is:

Travelling Salesman Problem – Step 6

2. We try to calculate the lower bound of the path starting at node 1 using the above resulting cost matrix. The lower bound is 0 as the matrix is already in reduced form, i.e., all rows and all columns have zero value.

Therefore, for node 1, the cost will be:

Cost = cost of node 0 +
        cost of the edge(0, 1) +
        lower bound of the path starting at node 1
     = 25 + 10 + 0 = 35

Let’s consider an edge from 0 —> 2

1. Change all the elements in row 0 and column 2 and at index (2, 0) to INFINITY (marked in red).

Travelling Salesman Problem – Step 7

The resulting cost matrix is:

Travelling Salesman Problem – Step 8

2. Now calculate the lower bound of the path starting at node 2 using the approach discussed earlier. The resultant matrix will be:

Travelling Salesman Problem – Step 9

Therefore, for node 2, the cost will be

Cost = cost of node 0 +
       cost of the edge(0, 2) +
       lower bound of the path starting at node 2
     = 25 + 17 + 11 = 53

Let’s consider an edge from 0 —> 3.

1. Change all the elements in row 0 and column 3 and at index (3, 0) to INFINITY (marked in red).

Travelling Salesman Problem – Step 10

The resulting cost matrix is:

Travelling Salesman Problem – Step 11

2. Now calculate the lower bound of the path starting at node 3 using the approach discussed earlier. The lower bound of the path starting at node 3 is 0 as it is already in reduced form, i.e., all rows and all columns have zero value.

Therefore, for node 3, the cost will be

Cost = cost of node 0 +
       cost of the edge(0, 3) +
       lower bound of the path starting at node 3
     = 25 + 0 + 0 = 25

Similarly, we calculate the cost of 0 —> 4. Its cost will be 31.

Now find a live node with the least estimated cost. Live nodes 1, 2, 3, and 4 have costs 35, 53, 25, and 31, respectively. The minimum among them is node 3, having cost 25. So, node 3 will be expanded further, as shown in the state-space tree diagram. After adding its children to the list of live nodes, find a live node with the least cost and expand it. Continue the search till a leaf is encountered in the space search tree. If a leaf is encountered, then the tour is completed, and we will return to the root node.

 
Following is the C++ implementation of the above idea:

Download  Run Code

Output:

1 —> 3
3 —> 4
4 —> 2
2 —> 5
5 —> 1
 
Total cost is 34

 
The proposed method, which uses Branch and Bound, is better because it prepares the matrices in different steps. At each step, the cost matrix is calculated. From the initial point, we know that what can be the minimum cost of the tour. The cost of the initial stages is not an exact cost, but it gives some idea because it is the approximated cost. At each step, it gives us a strong reason for which node we should travel the next and which one not. It gives this fact in terms of the cost of expanding a particular node.

 
References:

1. https://www.seas.gwu.edu/~bell/csci212/Branch_and_Bound.pdf
2. http://research.ijcaonline.org/volume65/number5/pxc3885866.pdf