Dynamic Programming TSP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

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 (eadeli@iust.ac.ir)

Representation of the graph

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 =

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 (eadeli@iust.ac.ir)

if

Compute the optimal tour

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)

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 (eadeli@iust.ac.ir)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy