Traveling Salesman Problem
Traveling Salesman Problem
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.
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.
Here are some of the most popular solutions to the Traveling Salesman Problem:
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.
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.
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.
Naive Solution
// update minimum
min_path = min(min_path, current_pathweight);
return min_path;
}
Dynamic Programming
Let the given set of vertices be {1, 2, 3, 4,….n}. Let us consider 1 as starting and ending
point of output. For every other vertex i (other than 1), we find the minimum cost path
with 1 as the starting point, i as the ending point and all vertices appearing exactly once.
Let the cost of this path be cost(i), the cost of corresponding Cycle would be cost(i) +
dist(i, 1) where dist(i, 1) is the distance from i to 1. Finally, we return the minimum of all
[cost(i) + dist(i, 1)] values. This looks simple so far. Now the question is how to get
cost(i)?
We start with all subsets of size 2 and calculate C(S, i) for all subsets where S is the
subset, then we calculate C(S, i) for all subsets S of size 3 and so on. Note that 1 must
be present in every subset.
C(S, i) = dist(1, i)
For a set of size n, we consider n-2 subsets each of size n-1 such that all subsets don’t
have nth in them.
Using the above recurrence relation, we can write dynamic programming based
solution. There are at most O(n*2n) subproblems, and each one takes linear time to
solve. The total running time is therefore O(n2*2n). The time complexity is much less
than O(n!), but still exponential. Space required is also exponential. So this approach is
also infeasible even for slightly higher number of vertices.
Resources:
https://blog.routific.com/travelling-salesman-problem
https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/
https://www.geeksforgeeks.org/traveling-salesman-problem-tsp-implementation/