CSC 305 VTL Lecture 06 2021

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Algorithm and Complexity

Course C CSC 305 / CSC 225: / Computer Science


Lecture 06: Travelling Sale Man problem

Name Prof. A. S. Sodiya

1
Introduction to TSM problem
 The problem TSP served as a particularly important example in the
early development of complexity theory. It was first formulated as an
optimization problem in the 19th century relative to the interpretation
where the vertices of G are understood to be cities, its edges as roads,
and their weights as distances (Schrijver 2005).
 Under this interpretation, an instance of the optimization problem thus
asks us to find the shortest tour by which all of the cities can be visited
exactly once.
 Variations of this problem arise not only in planning and logistical
applications, but also in a wide variety of other domains ranging from
the manufacturing microchips, to X-ray crystallography, to
computational biology (Gutin and Punnen 2002). Consequently much
effort has been put into finding efficient algorithms for solving both the
decision and optimization versions of TSP.
Understanding TSP
• The Travelling Salesman Problem (TSP) is the
challenge of finding the shortest yet most efficient
route for a person to take given a list of specific
destinations. It is a well-known algorithmic
problem in the fields of computer science and
operations research.
• There are obviously a lot of different routes to
choose from, but finding the best one—the one
that will require the least distance or cost—is
what mathematicians and computer scientists
have spent decades trying to solve for.
Understanding TSP …
• TSP has commanded so much attention because it’s so easy to
describe yet so difficult to solve. In fact, TSP belongs to the
class of combinatorial optimization problems known as NP-
complete. This means that TSP is classified as NP-
hard because it has no “quick” solution and the complexity of
calculating the best route will increase when you add more
destinations to the problem.
•  The problem can be solved by analyzing every round-trip
route to determine the shortest one. However, as the number of
destinations increases, the corresponding number of roundtrips
surpasses the capabilities of even the fastest computers. With
10 destinations, there can be more than 300,000 roundtrip
permutations and combinations. With 15 destinations, the
number of possible routes could exceed 87 billion.
Popular Travelling Salesman Problem Solutions
a. The Brute-Force Approach
The Brute Force approach, also known as the Naive Approach, calculates and
compares all possible permutations of routes or paths to determine the shortest
unique solution. To solve the TSP using the Brute-Force approach, you must calculate
the total number of routes and then draw and list all the possible routes. Calculate the
distance of each route and then choose the shortest one—this is the optimal solution. 
b. The Branch and Bound Method
This method breaks a problem to be solved into several sub-problems. It’s a system
for solving a series of sub-problems, each of which may have several possible
solutions and where the solution selected for one problem may have an effect on the
possible solutions of subsequent sub-problems. To solve the TSP using the Branch
and Bound method, you must choose a start node and then set bound to a very large
value (let’s say infinity). Select the cheapest arch between the unvisited and current
node and then add the distance to the current distance. Repeat the process while the
current distance is less then the bound. If the current distance is less than the bound,
you’re done. You may now add up the distance so that the bound will be equal to the
current distance. Repeat this process until all the arcs have been covered.
Popular Travelling Salesman Problem Solutions
c. The Nearest Neighbor Method
This is perhaps the simplest TSP heuristic. The key to this method is to
always visit the nearest destination and then go back to the first city
when all other cities are visited. To solve the TSP using this method,
choose a random city and then look for the closest unvisited city and go
there. Once you have visited all cities, you must return to the first city.  
Popular Travelling Salesman Problem Solutions
• d. Academic Solutions to TSP
• Academics have spent years trying to find the best solution to the Travelling
Salesman Problem The following solutions were published in recent years:
• Zero Suffix Method: Developed by Indian researchers, this method solves
the classical symmetric TSP. 
• Biogeography‐based Optimization Algorithm: This method is designed based
on the animals’ migration strategy to solve the problem of optimization. 
• Meta-Heuristic Multi Restart Iterated Local Search (MRSILS): The
proponents of this research asserted that the meta-heuristic MRSILS is more
efficient than the Genetic Algorithms when clusters are used. 
• Multi-Objective Evolutionary Algorithm: This method is designed for
solving multiple TSP based on NSGA-II. 
• Multi-Agent System: This system is designed to solve the TSP of N cities
with fixed resource. 
Real-world TSP Applications
• Despite the complexity of solving the Travelling Salesman
Problem, it still finds applications in all verticals. 
• For instance, efficient solutions found through the TSP are being
used in the last mile delivery. Last mile delivery refers to the
movement of goods from a transportation hub, such as a depot or a
warehouse, to the end customer’s choice of delivery. Last mile
delivery is the leading cost driver in the supply chain. Companies
usually shoulder some of the costs to better compete in the market.
In fact, a last mile delivery costs the company an average of $10.1,
but the customer only pays an average of $8.08. This is the reason
why businesses strive to minimize the cost of last mile delivery. 
• Vehicle routing problem is a generalized version of TSP
TSP Problem Statement
• A traveler needs to visit all the cities from a list, where
distances between all the cities are known and each city
should be visited just once. What is the shortest possible
route that he visits each city exactly once and returns to the
origin city?
Solution to TSP
• Travelling salesman problem is the most notorious computational problem.
We can use brute-force approach to evaluate every possible tour and select
the best one. For n number of vertices in a graph, there are (n - 1)! number of
possibilities.
• Instead of brute-force using dynamic programming approach, the solution
can be obtained in lesser time, though there is no polynomial time algorithm.
• Let us consider a graph G = (V, E), where V is a set of cities and E is a set of
weighted edges. An edge e(u, v) represents that vertices u and v are
connected. Distance between vertex u and v is d(u, v), which should be non-
negative.
• Suppose we have started at city 1 and after visiting some cities now we are in
city j. Hence, this is a partial tour. We certainly need to know j, since this will
determine which cities are most convenient to visit next. We also need to
know all the cities visited so far, so that we don't repeat any of them. Hence,
this is an appropriate sub-problem.
Solution to TSP…
For a subset of cities S Є {1, 2, 3, ... , n} that includes 1, and j Є S, let C(S, j) be
the length of the shortest path visiting each node in S exactly once, starting at 1
and ending at j.

When |S| > 1, we define C(S, 1) = ∝ since the path cannot start and end at 1.

Now, let express C(S, j) in terms of smaller sub-problems. We need to start at 1


and end at j. We should select the next city in such a way that

C(S,j)=minC(S−{j},i)+d(i,j)wherei∈Sandi≠jc(S,j)=minC(s−{j},i)
+d(i,j)wherei∈Sandi≠j
TSP Algorithm
Algorithm: Traveling-Salesman-Problem
C ({1}, 1) = 0
for s = 2 to n do
for all subsets S Є {1, 2, 3, … , n} of size s and containing 1
C (S, 1) = ∞
for all j Є S and j ≠ 1
C (S, j) = min {C (S – {j}, i) + d(i, j) for i Є S and i ≠ j}
Return minj C ({1, 2, 3, …, n}, j) + d(j, i)
Analysis of Solution
Analysis
There are at the most 2n.n sub-problems and each one takes linear time to solve.
Therefore, the total running time is O(2n.n2)
Example
1 2 3 4
1 0 10 15 20
2 5 0 9 10
3 6 13 0 12
4 8 8 9 0

In the following example, we will illustrate the steps to solve the travelling salesman problem.

From the above graph, the following table is prepared.


S=Φ
Cost(2,Φ,1)=d(2,1)=5Cost(2,Φ,1)=d(2,1)=5Cost(2,Φ,1)=d(2,1)=5Cost(2,Φ,1)=d(2,1)=5
Cost(3,Φ,1)=d(3,1)=6Cost(3,Φ,1)=d(3,1)=6Cost(3,Φ,1)=d(3,1)=6Cost(3,Φ,1)=d(3,1)=6
Cost(4,Φ,1)=d(4,1)=8Cost(4,Φ,1)=d(4,1)=8
Example…
S=1
Cost(i,s)=min{Cost(j,s–(j))+d[i,j]}Cost(i,s)=min{Cost(j,s)−(j))+d[i,j]}
Cost(2,{3},1)=d[2,3]+Cost(3,Φ,1)=9+6=15cost(2,{3},1)=d[2,3]+cost(3,Φ,1)=9+6=15
Cost(2,{4},1)=d[2,4]+Cost(4,Φ,1)=10+8=18cost(2,{4},1)=d[2,4]+cost(4,Φ,1)=10+8=18
Cost(3,{2},1)=d[3,2]+Cost(2,Φ,1)=13+5=18cost(3,{2},1)=d[3,2]+cost(2,Φ,1)=13+5=18
Cost(3,{4},1)=d[3,4]+Cost(4,Φ,1)=12+8=20cost(3,{4},1)=d[3,4]+cost(4,Φ,1)=12+8=20
Cost(4,{3},1)=d[4,3]+Cost(3,Φ,1)=9+6=15cost(4,{3},1)=d[4,3]+cost(3,Φ,1)=9+6=15
Cost(4,{2},1)=d[4,2]+Cost(2,Φ,1)=8+5=13cost(4,{2},1)=d[4,2]+cost(2,Φ,1)=8+5=13
S=2
Cost(2,{3,4},1)=⎧⎩⎨d[2,3]+Cost(3,{4},1)=9+20=29d[2,4]+Cost(4,
{3},1)=10+15=25=25Cost(2,{3,4},1){d[2,3]+cost(3,{4},1)=9+20=29d[2,4]+Cost(4,
{3},1)=10+15=25=25
Cost(3,{2,4},1)=⎧⎩⎨d[3,2]+Cost(2,{4},1)=13+18=31d[3,4]+Cost(4,
{2},1)=12+13=25=25Cost(3,{2,4},1){d[3,2]+cost(2,{4},1)=13+18=31d[3,4]+Cost(4,
{2},1)=12+13=25=25
Cost(4,{2,3},1)=⎧⎩⎨d[4,2]+Cost(2,{3},1)=8+15=23d[4,3]+Cost(3,{2},1)=9+18=27=23Cost(4,
{2,3},1){d[4,2]+cost(2,{3},1)=8+15=23d[4,3]+Cost(3,{2},1)=9+18=27=23
Example…
Example…

The minimum cost path is 35.


Start from cost {1, {2, 3, 4}, 1}, we get the minimum value for d
[1, 2]. When s = 3, select the path from 1 to 2 (cost is 10) then go
backwards. When s = 2, we get the minimum value for d [4, 2].
Select the path from 2 to 4 (cost is 10) then go backwards.
When s = 1, we get the minimum value for d [4, 3]. Selecting
path 4 to 3 (cost is 9), then we shall go to then go to s = Φ step.
We get the minimum value for d [3, 1] (cost is 6).

You might also like