Dynamic Programming TSP
Dynamic Programming TSP
Dynamic Programming TSP
V. Balasubramanian
`
`
`
`
Algorithms (eadeli@iust.ac.ir)
Algorithms (eadeli@iust.ac.ir)
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 (eadeli@iust.ac.ir)
The algorithm
Length of an optimal tour =
2 j n
Algorithms (eadeli@iust.ac.ir)
if
Algorithms (eadeli@iust.ac.ir)
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 (eadeli@iust.ac.ir)
A Theorem
`
For all n 1
n
n 1
k = n 2
k =1 k
n
Algorithms (eadeli@iust.ac.ir)
`
`
`
Algorithms (eadeli@iust.ac.ir)