The Traveling Salesman Problem (TSP)
Maryam Alipour
This is a student project for the subject Network Algorithms in the Master’s course of Applied
Mathematics in Digital Media
Hochschule of Miettweida, The University of applied Sciences
Winter semester 2015/16
Abstract
Traveling salesman problem (TSP) is a well-known problem which has been
under study and work by many mathematicians during the past centuries. There are
several algorithms that result in exact or optimal answers for TSP. In this project
after description and give some necessary definitions, we are going to analyze the
dynamic programming methods to solve TSP.
Introduction
Imagine a salesman who is about to go on a trip to sell some product. He has to
go to several cities during his tour, and of course he prefers to visit each city only
once, because he has to take the traveling costs into account and makes his journey
as short as possible.
Thus, he faces the following problem: “find the shortest tour starting from his
hometown, visiting every other city exactly once, and then returning home.” This is
the famous traveling salesman problem or in short TSP.
TSP belongs to those kind of problems that are really easy to understand, but
unfortunately much more difficult to solve. Actually, if our salesman wants to visit
only 4 or 5 cities, he could probably guess the optimal tour himself, but what if his
tour consists of like 60 cities? It would be interesting to know that the number of
possible tours through 60 cities is actually more than the number of all existing atoms
in the whole universe!
So, the real question here, is to find an efficient algorithm that can help our
salesman with his problem.
History
The exact origins of the traveling salesman problem are unclear. It’s interesting
that a handbook for real traveling salesmen from 1832 mentions the problem and
also includes some example tours through Germany and Switzerland, but contains
no mathematical solution.
TSP was mathematically formulated in the 1800’s for the first time by the famous
Irish mathematician W.R.Hamilton, and independently by the British mathematician
Thomas Kirkman.
The general form of TSP has been studied during 1930’s by mathematicians and
scientists in the Vienna, Harvard, and Prinston Universities.
Modeling TSP as a Graph Problem
To talk about TSP as a graph problem, it is essential to define some special types
of graph:
-Undirected Graph
An undirected graph is a graph in which, edges have no direction, and the edge
(x,y) is the same as the edge (y,x).
-Weighted Graph
A weighted graph is a graph in which, a number (the weight) is assigned to each
edge. Such weights might represent for example costs, lengths, or capacities,
depending on the problem we are working on.
-Complete Graph
A complete graph is a graph in which, each pair of vertices are connected to each
other by an edge. In other words, a complete graph contains all possible edges.
In general, TSP can be modeled as an undirected, weighted, complete graph such
that our cities form the graph’s vertices, the paths between cities form the graph’s
edges, and the distance between each pair of cities form the weight of the respected
edge. Clearly, it is a minimization problem, starting and ending at a specified vertex,
after visiting all other vertices exactly once. As it has been mentioned we suppose
our problem forms a complete graph and it is exactly where the distance between
each pair of cities is given, but if we had a case that no path exists between some of
city pairs, we can just add arbitrarily long edges to the graph that represents our
problem, so it becomes a complete graph, clearly without affecting the length of the
optimal tour.
Introduntion of the main categories of TSP
Mathematicians have been working on different models of TSP, during the past
decades. Here is the definition of the main and most applicable TSP’s:
- Metric TSP
In the metric TSP, which is also known as Δ-TSP (delta-TSP), the given distances
between cities satisfy the triangle inequality. It means that in a metric TSP, it is
required that the direct connection from city x to the city z, be never longer than the
route from x to z via city y.
- Symmetric TSP
In the symmetric TSP, the distance between two cities is the same in each
opposite direction, and the problem is forming an undirected graph.
- Asymmetric TSP
In the asymmetric TSP, paths may not exist in both directions, or the distance
between two cities might be different in opposite directions, and obviously the
problem is forming a directed graph. One-way streets, and airfares with different
departure and arrival fees, are some examples of how modeling TSP as a symmetry
could be broken down in real life.
- Shortest Hamiltonian Path
In graph theory, a Hamiltonian path is a path in an undirected or directed graph,
that visits all vertices exactly once, and a Hamiltonian cycle is a cycle that visits all
vertices exactly once. So, when we model TSP as a graph problem, clearly we are
looking for the shortest Hamiltonian cycle. Also, finding Hamiltonian paths and
Hamiltonian cycles in a graph are actually equivalent and it’s been explained below:
If we had a Hamiltonian cycle, the corresponding Hamiltonian path would be the
Hamiltonian path which appears after removing exactly one edge out of our
Hamiltonian cycle, and on the other hand if we had a Hamiltonian path, adding the
edge between the two end vertices of our path, creates a Hamiltonian cycle.
The important thing which is remained to be proved is that whether having a
method which finds the shortest Hamiltonian path gives us our desired shortest
Hamiltonian cycle or not. Imagine that we can find the shortest Hamiltonian path
somehow. Now, consider the graph G and suppose v be a vertex of G, to find the
shortest Hamiltonian cycle, we add three vertices x, y, and z to our graph and
transform it to a new graph like Gʹ. These new vertices are going to get removed
later, so they do not affect the length of our path or cycle. Now we define the set of
the edges of the graph Gʹ as the set
Eʹ = {(x,v)} ∪{(z,y)} ∪ {(y,w)│(v,w) is an edge of G}
Also, the length of each one of those edges of form (y,w) in Eʹ, is defined to be
the same as the length of the edge (v,w) of G. Clearly, the shortest Hamiltonian path
of the graph Gʹ, would have the vertices x and z as its end points since the degree of
these vertices are 1. Also, suppose this path be like x-v-u1- ∙∙∙ -u2-y-z , such that
between v and y, all vertices of G-v are visited once. Now is the trick time! We
remove the edges (x,v), (u2,y), and (y,z) from the shortest Hamiltonian path of the
graph Gʹ, and the remaining path, by adding the edge (u2,v) forms a Hamiltonian
cycle which we claim is the shortest Hamiltonian cycle in G. If this cycle is not the
shortest Hamiltonian cycle, there would be some other order in visiting vertices that
forms a shorter cycle, but this event contradicts with the shortest Hamiltonian path
of Gʹ having the shortest length, and this finishes the proof.
-Bottleneck TSP
The bottleneck traveling salesman problem asks for a tour in which the largest
edge is as small as possible. Actually, it’s stated as the following question: find the
Hamiltonian cycle in a weighted graph which minimizes the weight of the most
weighty edge of the cycle.
Analysis of some special cases
Sometimes it is really helpful if we could transform the general form of TSP into
a metric TSP. To do so, for a given TSP instance with n cities, we define:
dij := the distance between city i and city j; clearly for all i,j dij≥0.
Now, let M := max { dij │ 0≤i,j≤n }.
We define the metric TSP instance by introducing the new distances dʹij:= dij + M.
To see that these dʹij ‘s form an appropriate metric instance, let i,j,k be three cities
which are chosen arbitrarily, then:
dʹij + dʹjk = (dij + M) + (djk + M) ≥ 2M ≥ dik + M = dʹik
Since any tour uses exactly n edges, this transformation adds exactly the amount nM
to the length of any tour, and obviously doesn’t affect the correctness of them being
Hamiltonian cycles.
Up to now, we’ve showed any TSP instance could be transformed to a metric
TSP instance. Now, we want to find out if in the general form of TSP, we just remove
the restriction of visiting all vertices “exactly once”, and suppose that we have to
find the solution with the new restriction of visiting all cities “at least once”, whether
finding the optimal tour gets easier or not.
Here, we will prove that as long as our TSP instance is metric, finding an answer
for both versions of TSP are equivalent, and since in the previous section, we proved
finding the shortest Hamiltonian cycle which is our optimal tour, could be the same
as finding the shortest Hamiltonian path, the following result holds in general.
Consider any optimal tour R where some vertices are visited more than once and
let vertex i be one of those vertices, and suppose vertices j and k be the vertices that
are visited right before and after the vertex i.
Now, delete the edges (j,i) and (i,k) from the tour, and add the edge (j,k) instead.
Since, the graph is metric, the tour weight stays the same as before, or it might
decrease (because due to the definition of a metric instance: djk ≤ dji + dik ), but if it
decreases, then it contradicts the optimality of the tour R, so the weight of the tour
does not change in spite of the fact that we deleted 2 edges from the tour and add
one, instead. Now, the vertex i has been visited one time less in our new tour.
Repeating this method, as long as there is no vertex which is visited more than once,
gives us the optimal tour where all vertices have been visited exactly once.
So far, we proved that in a metric TSP, every optimal tour that visits each vertex
at least once is somehow equivalent to an optimal tour which visits each vertex
exactly once. Clearly, the reverse holds since visiting all vertices exactly once is
more restricted than visiting them at least once, so the proof is complete.
Dynamic Programming
Dynamic programming refers to a very large class of algorithms. The main idea
is to break a large problem, or more often a complex problem down into a collection
of hopefully simpler or smaller sub problems. The trick is to solve (exactly or
approximately) those sub problems just once, and storing their solutions. Any time,
the same problem occurs again, instead of re-computing its solution, it’s enough to
simply look into the stored solution. The act of storing solutions of sub problems is
called memorization.
Dynamic programming algorithms are widely used for optimization, for instance
finding the fastest way to multiply many matrices, or finding the shortest path
between two specified points under particular circumstances.
To describe what exactly dynamic programming algorithm does, we can say in
the simplest way, it examines the previously solved sub problems, then combines
their solutions, and finally comes with the best solution for the given problem.
Dynamic Programming Formulation for TSP
Consider the problem as a multi-stage problem. Without loss of generality, since
the tour is round trip, fix the origin at some city like 0. Suppose that at certain stage
of an optimal tour, starting at 0, our salesman has reached to the city i, and there are
remained k cities j1, j2, … , jk to visit before returning to the city 0. Then it is clear
that the path from i to 0, through the cities j1, j2, … , jk must be of minimum length,
because otherwise the whole tour can not be optimal.
Now, we define the function f as below:
f( i ; j1, j2, … , jk) := length of the path of minimum length, starting from i, visiting
each of remaining unvisited cities j1, j2, … , jk exactly once, and returning to the city
0. Clearly, if we could obtain f(0;1,…,n), we could efficiently solve TSP.
Then define:
dij := the distance between city i and city j.
Then, as a consequence:
f( i ; j1, j2, … , jk) = min 1≤m≤k { + f(jm ; j1, j2,…, jm-1, jm+1,…, jk)} (*)
And also:
f(i ; j) = + dj0 (**)
From (**), first we can obtain the exact amount of f(i ; j), then simply through
(*), we can find f(i;j1,j2), and so on, until f(0; 1,…, n) is obtained. The sequence of
values of m in (*) gives us the desired minimal path.
In each stage, there is exactly one current city (the city that our salesman is
visiting in that stage), so there are n possible choices for the current city. Also, each
city is either visited or unvisited, so there are 2n
choices for that, and it says that the
total number of sub problems is n.2n
in this method. Each one of these sub problems
could be solved in linear time, so the running time of the solution is therefore
O(n2
.2n
).
Example
Consider the complete graph K5 where 1, 2, 3, 4, and 5 are the vertices, and the
length of the edges is listed below:
d12=1 ; d13=10 ; d14=10 ; d15=1
d21=1 ; d23=1 ; d24=10 ; d25=10
d31=10 ; d32=1 ; d34=1 ; d35=10
d41=10 ; d42=10 ; d43=1 ; d45=1
d51=1 ; d52=10 ; d53=10 ; d54=1
To find the shortest Hamiltonian cycle, or in other words to find the optimal tour
(which is obviously the tour 1-2-3-4-5-1 that is also the same as the tour 1-5-4-3-2-
1 with the total length of 5), by the mentioned method i.e. using dynamic
programming, actually, we need to find f(1; 2, 3, 4, 5). So:
First, we must calculate all f(i ; j)’s, where 2≤ i , j ≤5 :
f(2 ; 3) = f(2 ; 5) = f(3 ; 4) = f(3 ; 5) = f(4 ; 2) = f(4 ; 3) = f(5 ; 2) = f(5 ; 4) = 11
f(2 ; 4) = f(5 ; 3) = 20
f(3 ; 2) = f(4 ; 5) = 2
Next step, would be to find all f(i ; j, k)’s, where 2 ≤ i ≤5, 2≤ j < k ≤ 5 :
f(3 ; 4, 5) = f(4 ; 2, 3) = 3
f(2 ; 3, 4) = f(2 ; 3, 5) = f(2 ; 4, 5) = f(3 ; 2, 4) = f(3 ; 2, 5) = f(4 ; 2, 5) = f(4 ; 3, 5) =
f(5 ; 2, 3)=f(5 ; 2, 4)=f(5 ; 3, 4)=12
Then, we need to calculate all f(i ; j, k, l)’s, where 2 ≤ i≤5 ,2≤ j < k < l ≤ 5 :
f(2 ; 3, 4, 5) = f(5 ; 2, 3, 4) = 4
f(3 ; 2, 4, 5) = f(4 ; 2, 3, 5) = 13
And finally the answer is the amount of f(1 ; 2, 3, 4, 5) :
f(1 ; 2, 3, 4, 5) = 5
The length of the optimal tour, as it was expected, is 5 and the sequence of m’s is
2,3,4,5 or 5,4,3,2 and both sequences could make our desired path.
Conclusion
Finding the exact answer for the traveling salesman problem is time consuming,
and when the number of cities gets larger, the running time of solving that, even by
the algorithm using dynamic programming gets really large. But sometimes it’s
necessary to reach the exact answer and it is clear that using this algorithm, compared
to checking the length of all possible cyclic permutations of cities, could be very
time saving.
References
[1] Nilsson Christian “Heuristics for the traveling salesman problem” Linköping
University
[2] Maredina Anne (2010) History, Analysis, and Implementation of the traveling
salesman problem (TSP) and related problems Houston University of Houston-
Downtown
[3] Fannon Paul, Kadelburg Vesna, Wooley Ben, Ward Stephen (2013) Discrete
Mathematics Cambridge Cambridge University Press
[4] Carman H. Thomas, Leiserson E. Charles, Rivest L. Ronald, Stein Clifford
Introduction to Algorithms Second Edition McGrawHill Book Company
[5] Teofilo F.Gonzalez (2007) Handbook of Approximation Algorithms and
Metaheuristics New York Chapman & Hall/CRC
[6] http://mathworld.wolfram.com/TravelingSalesmanProblem.html
[7] https://en.wikipedia.org/wiki/Travelling_salesman_problem
[8] https://www.quora.com/How-do-I-solve-the-traveling-salesman-problem-using-
dynamic-programming
[9]http://math.stackexchange.com/questions/7130/reduction-from-hamiltonian-
cycle-to-hamiltonian-path/1290804#1290804

The Traveling Salesman Problem

  • 1.
    The Traveling SalesmanProblem (TSP) Maryam Alipour This is a student project for the subject Network Algorithms in the Master’s course of Applied Mathematics in Digital Media Hochschule of Miettweida, The University of applied Sciences Winter semester 2015/16 Abstract Traveling salesman problem (TSP) is a well-known problem which has been under study and work by many mathematicians during the past centuries. There are several algorithms that result in exact or optimal answers for TSP. In this project after description and give some necessary definitions, we are going to analyze the dynamic programming methods to solve TSP. Introduction Imagine a salesman who is about to go on a trip to sell some product. He has to go to several cities during his tour, and of course he prefers to visit each city only once, because he has to take the traveling costs into account and makes his journey as short as possible. Thus, he faces the following problem: “find the shortest tour starting from his hometown, visiting every other city exactly once, and then returning home.” This is the famous traveling salesman problem or in short TSP. TSP belongs to those kind of problems that are really easy to understand, but unfortunately much more difficult to solve. Actually, if our salesman wants to visit only 4 or 5 cities, he could probably guess the optimal tour himself, but what if his tour consists of like 60 cities? It would be interesting to know that the number of possible tours through 60 cities is actually more than the number of all existing atoms in the whole universe! So, the real question here, is to find an efficient algorithm that can help our salesman with his problem.
  • 2.
    History The exact originsof the traveling salesman problem are unclear. It’s interesting that a handbook for real traveling salesmen from 1832 mentions the problem and also includes some example tours through Germany and Switzerland, but contains no mathematical solution. TSP was mathematically formulated in the 1800’s for the first time by the famous Irish mathematician W.R.Hamilton, and independently by the British mathematician Thomas Kirkman. The general form of TSP has been studied during 1930’s by mathematicians and scientists in the Vienna, Harvard, and Prinston Universities. Modeling TSP as a Graph Problem To talk about TSP as a graph problem, it is essential to define some special types of graph: -Undirected Graph An undirected graph is a graph in which, edges have no direction, and the edge (x,y) is the same as the edge (y,x). -Weighted Graph A weighted graph is a graph in which, a number (the weight) is assigned to each edge. Such weights might represent for example costs, lengths, or capacities, depending on the problem we are working on. -Complete Graph A complete graph is a graph in which, each pair of vertices are connected to each other by an edge. In other words, a complete graph contains all possible edges. In general, TSP can be modeled as an undirected, weighted, complete graph such that our cities form the graph’s vertices, the paths between cities form the graph’s edges, and the distance between each pair of cities form the weight of the respected edge. Clearly, it is a minimization problem, starting and ending at a specified vertex, after visiting all other vertices exactly once. As it has been mentioned we suppose
  • 3.
    our problem formsa complete graph and it is exactly where the distance between each pair of cities is given, but if we had a case that no path exists between some of city pairs, we can just add arbitrarily long edges to the graph that represents our problem, so it becomes a complete graph, clearly without affecting the length of the optimal tour. Introduntion of the main categories of TSP Mathematicians have been working on different models of TSP, during the past decades. Here is the definition of the main and most applicable TSP’s: - Metric TSP In the metric TSP, which is also known as Δ-TSP (delta-TSP), the given distances between cities satisfy the triangle inequality. It means that in a metric TSP, it is required that the direct connection from city x to the city z, be never longer than the route from x to z via city y. - Symmetric TSP In the symmetric TSP, the distance between two cities is the same in each opposite direction, and the problem is forming an undirected graph. - Asymmetric TSP In the asymmetric TSP, paths may not exist in both directions, or the distance between two cities might be different in opposite directions, and obviously the problem is forming a directed graph. One-way streets, and airfares with different departure and arrival fees, are some examples of how modeling TSP as a symmetry could be broken down in real life. - Shortest Hamiltonian Path In graph theory, a Hamiltonian path is a path in an undirected or directed graph, that visits all vertices exactly once, and a Hamiltonian cycle is a cycle that visits all vertices exactly once. So, when we model TSP as a graph problem, clearly we are looking for the shortest Hamiltonian cycle. Also, finding Hamiltonian paths and Hamiltonian cycles in a graph are actually equivalent and it’s been explained below: If we had a Hamiltonian cycle, the corresponding Hamiltonian path would be the Hamiltonian path which appears after removing exactly one edge out of our
  • 4.
    Hamiltonian cycle, andon the other hand if we had a Hamiltonian path, adding the edge between the two end vertices of our path, creates a Hamiltonian cycle. The important thing which is remained to be proved is that whether having a method which finds the shortest Hamiltonian path gives us our desired shortest Hamiltonian cycle or not. Imagine that we can find the shortest Hamiltonian path somehow. Now, consider the graph G and suppose v be a vertex of G, to find the shortest Hamiltonian cycle, we add three vertices x, y, and z to our graph and transform it to a new graph like Gʹ. These new vertices are going to get removed later, so they do not affect the length of our path or cycle. Now we define the set of the edges of the graph Gʹ as the set Eʹ = {(x,v)} ∪{(z,y)} ∪ {(y,w)│(v,w) is an edge of G} Also, the length of each one of those edges of form (y,w) in Eʹ, is defined to be the same as the length of the edge (v,w) of G. Clearly, the shortest Hamiltonian path of the graph Gʹ, would have the vertices x and z as its end points since the degree of these vertices are 1. Also, suppose this path be like x-v-u1- ∙∙∙ -u2-y-z , such that between v and y, all vertices of G-v are visited once. Now is the trick time! We remove the edges (x,v), (u2,y), and (y,z) from the shortest Hamiltonian path of the graph Gʹ, and the remaining path, by adding the edge (u2,v) forms a Hamiltonian cycle which we claim is the shortest Hamiltonian cycle in G. If this cycle is not the shortest Hamiltonian cycle, there would be some other order in visiting vertices that forms a shorter cycle, but this event contradicts with the shortest Hamiltonian path of Gʹ having the shortest length, and this finishes the proof. -Bottleneck TSP The bottleneck traveling salesman problem asks for a tour in which the largest edge is as small as possible. Actually, it’s stated as the following question: find the Hamiltonian cycle in a weighted graph which minimizes the weight of the most weighty edge of the cycle. Analysis of some special cases Sometimes it is really helpful if we could transform the general form of TSP into a metric TSP. To do so, for a given TSP instance with n cities, we define: dij := the distance between city i and city j; clearly for all i,j dij≥0.
  • 5.
    Now, let M:= max { dij │ 0≤i,j≤n }. We define the metric TSP instance by introducing the new distances dʹij:= dij + M. To see that these dʹij ‘s form an appropriate metric instance, let i,j,k be three cities which are chosen arbitrarily, then: dʹij + dʹjk = (dij + M) + (djk + M) ≥ 2M ≥ dik + M = dʹik Since any tour uses exactly n edges, this transformation adds exactly the amount nM to the length of any tour, and obviously doesn’t affect the correctness of them being Hamiltonian cycles. Up to now, we’ve showed any TSP instance could be transformed to a metric TSP instance. Now, we want to find out if in the general form of TSP, we just remove the restriction of visiting all vertices “exactly once”, and suppose that we have to find the solution with the new restriction of visiting all cities “at least once”, whether finding the optimal tour gets easier or not. Here, we will prove that as long as our TSP instance is metric, finding an answer for both versions of TSP are equivalent, and since in the previous section, we proved finding the shortest Hamiltonian cycle which is our optimal tour, could be the same as finding the shortest Hamiltonian path, the following result holds in general. Consider any optimal tour R where some vertices are visited more than once and let vertex i be one of those vertices, and suppose vertices j and k be the vertices that are visited right before and after the vertex i. Now, delete the edges (j,i) and (i,k) from the tour, and add the edge (j,k) instead. Since, the graph is metric, the tour weight stays the same as before, or it might decrease (because due to the definition of a metric instance: djk ≤ dji + dik ), but if it decreases, then it contradicts the optimality of the tour R, so the weight of the tour does not change in spite of the fact that we deleted 2 edges from the tour and add one, instead. Now, the vertex i has been visited one time less in our new tour. Repeating this method, as long as there is no vertex which is visited more than once, gives us the optimal tour where all vertices have been visited exactly once. So far, we proved that in a metric TSP, every optimal tour that visits each vertex at least once is somehow equivalent to an optimal tour which visits each vertex exactly once. Clearly, the reverse holds since visiting all vertices exactly once is more restricted than visiting them at least once, so the proof is complete.
  • 6.
    Dynamic Programming Dynamic programmingrefers to a very large class of algorithms. The main idea is to break a large problem, or more often a complex problem down into a collection of hopefully simpler or smaller sub problems. The trick is to solve (exactly or approximately) those sub problems just once, and storing their solutions. Any time, the same problem occurs again, instead of re-computing its solution, it’s enough to simply look into the stored solution. The act of storing solutions of sub problems is called memorization. Dynamic programming algorithms are widely used for optimization, for instance finding the fastest way to multiply many matrices, or finding the shortest path between two specified points under particular circumstances. To describe what exactly dynamic programming algorithm does, we can say in the simplest way, it examines the previously solved sub problems, then combines their solutions, and finally comes with the best solution for the given problem. Dynamic Programming Formulation for TSP Consider the problem as a multi-stage problem. Without loss of generality, since the tour is round trip, fix the origin at some city like 0. Suppose that at certain stage of an optimal tour, starting at 0, our salesman has reached to the city i, and there are remained k cities j1, j2, … , jk to visit before returning to the city 0. Then it is clear that the path from i to 0, through the cities j1, j2, … , jk must be of minimum length, because otherwise the whole tour can not be optimal. Now, we define the function f as below: f( i ; j1, j2, … , jk) := length of the path of minimum length, starting from i, visiting each of remaining unvisited cities j1, j2, … , jk exactly once, and returning to the city 0. Clearly, if we could obtain f(0;1,…,n), we could efficiently solve TSP. Then define:
  • 7.
    dij := thedistance between city i and city j. Then, as a consequence: f( i ; j1, j2, … , jk) = min 1≤m≤k { + f(jm ; j1, j2,…, jm-1, jm+1,…, jk)} (*) And also: f(i ; j) = + dj0 (**) From (**), first we can obtain the exact amount of f(i ; j), then simply through (*), we can find f(i;j1,j2), and so on, until f(0; 1,…, n) is obtained. The sequence of values of m in (*) gives us the desired minimal path. In each stage, there is exactly one current city (the city that our salesman is visiting in that stage), so there are n possible choices for the current city. Also, each city is either visited or unvisited, so there are 2n choices for that, and it says that the total number of sub problems is n.2n in this method. Each one of these sub problems could be solved in linear time, so the running time of the solution is therefore O(n2 .2n ). Example Consider the complete graph K5 where 1, 2, 3, 4, and 5 are the vertices, and the length of the edges is listed below: d12=1 ; d13=10 ; d14=10 ; d15=1 d21=1 ; d23=1 ; d24=10 ; d25=10 d31=10 ; d32=1 ; d34=1 ; d35=10 d41=10 ; d42=10 ; d43=1 ; d45=1 d51=1 ; d52=10 ; d53=10 ; d54=1 To find the shortest Hamiltonian cycle, or in other words to find the optimal tour (which is obviously the tour 1-2-3-4-5-1 that is also the same as the tour 1-5-4-3-2- 1 with the total length of 5), by the mentioned method i.e. using dynamic programming, actually, we need to find f(1; 2, 3, 4, 5). So: First, we must calculate all f(i ; j)’s, where 2≤ i , j ≤5 : f(2 ; 3) = f(2 ; 5) = f(3 ; 4) = f(3 ; 5) = f(4 ; 2) = f(4 ; 3) = f(5 ; 2) = f(5 ; 4) = 11
  • 8.
    f(2 ; 4)= f(5 ; 3) = 20 f(3 ; 2) = f(4 ; 5) = 2 Next step, would be to find all f(i ; j, k)’s, where 2 ≤ i ≤5, 2≤ j < k ≤ 5 : f(3 ; 4, 5) = f(4 ; 2, 3) = 3 f(2 ; 3, 4) = f(2 ; 3, 5) = f(2 ; 4, 5) = f(3 ; 2, 4) = f(3 ; 2, 5) = f(4 ; 2, 5) = f(4 ; 3, 5) = f(5 ; 2, 3)=f(5 ; 2, 4)=f(5 ; 3, 4)=12 Then, we need to calculate all f(i ; j, k, l)’s, where 2 ≤ i≤5 ,2≤ j < k < l ≤ 5 : f(2 ; 3, 4, 5) = f(5 ; 2, 3, 4) = 4 f(3 ; 2, 4, 5) = f(4 ; 2, 3, 5) = 13 And finally the answer is the amount of f(1 ; 2, 3, 4, 5) : f(1 ; 2, 3, 4, 5) = 5 The length of the optimal tour, as it was expected, is 5 and the sequence of m’s is 2,3,4,5 or 5,4,3,2 and both sequences could make our desired path. Conclusion Finding the exact answer for the traveling salesman problem is time consuming, and when the number of cities gets larger, the running time of solving that, even by the algorithm using dynamic programming gets really large. But sometimes it’s necessary to reach the exact answer and it is clear that using this algorithm, compared to checking the length of all possible cyclic permutations of cities, could be very time saving. References [1] Nilsson Christian “Heuristics for the traveling salesman problem” Linköping University
  • 9.
    [2] Maredina Anne(2010) History, Analysis, and Implementation of the traveling salesman problem (TSP) and related problems Houston University of Houston- Downtown [3] Fannon Paul, Kadelburg Vesna, Wooley Ben, Ward Stephen (2013) Discrete Mathematics Cambridge Cambridge University Press [4] Carman H. Thomas, Leiserson E. Charles, Rivest L. Ronald, Stein Clifford Introduction to Algorithms Second Edition McGrawHill Book Company [5] Teofilo F.Gonzalez (2007) Handbook of Approximation Algorithms and Metaheuristics New York Chapman & Hall/CRC [6] http://mathworld.wolfram.com/TravelingSalesmanProblem.html [7] https://en.wikipedia.org/wiki/Travelling_salesman_problem [8] https://www.quora.com/How-do-I-solve-the-traveling-salesman-problem-using- dynamic-programming [9]http://math.stackexchange.com/questions/7130/reduction-from-hamiltonian- cycle-to-hamiltonian-path/1290804#1290804