Dynamic Programming-TSP
V. Balasubramanian
The traveling sales person problem
Tour (Hamilton circuit): a path from a vertex to itself that
passes through each of the other vertices exactly once
Optimal tour: such a path of minimum length
Brute force algorithm is
(n-1)(n-2)1 = (n-1)!
Principle of optimality applies
`
`
`
`
Algorithms ([email protected])
Representation of the graph
Algorithms ([email protected])
Preparation
Let D[vi][A] = length of a shortest path from vi to v1
passing through each vertex in A exactly once
Compute D[v2][A] when A = {v3} and A = {v3, v4}
`
`
Algorithms ([email protected])
The algorithm
Length of an optimal tour =
Minimum (W [1][ j ] + D[v ][V {v , v }])
j
2 j n
In general for i 1 and vi not in A
D[vi ][ A] = Minimum (W [i ][ j ] + D[v j ][ A {v j}])
j:v j A
D[vi ][ ] = W [i ][1]
Algorithms ([email protected])
if
Compute the optimal tour
Algorithms ([email protected])
The Algorithm
Algorithm 3.11: The Dynamic Programming Algorithm for the Traveling Salesperson Problem
void travel (int n, const number W[][], index P[][], number& minlength)
{
index i, j, k;
number D[1..n][subset of V - {v1}];
for (i = 2; i <= n; i++) D[i][] = W[i][1];
for (k = 1; k <= n - 2; k++)
for (all subsets A V - {v1} containing k vertices)
for (i such that i 1 and vi is not in A){
D[i][A] = minimum (W[i][j] + D[j][A - {vj}]);
j: vj A
P[i][A] = value of j that gave the minimum;
}
D[1][V - {v1}] = minimum (W[1][j] + D[j][V - {v1, vj}]);
2jn
P[1][V - {v1}] = value of j that gave the minimum;
minlength = D[1][V - {v1}];
}
Algorithms ([email protected])
A Theorem
`
For all n 1
n
n 1
k = n 2
k =1 k
n
Algorithms ([email protected])
Every-case time complexity
Basic operation: the instructions executed for each value
of vj
n, the number of vertices in the graph
Time complexity
T(n) = (n-1)(n-2)2n-3 (n22n)
Memory complexity:
M(n) = 2 n2n-1 = n2n (n2n)
`
`
`
Algorithms ([email protected])