0% found this document useful (0 votes)
40 views

Optimization Report

The document discusses the traveling salesman problem (TSP) in optimization. TSP aims to find the shortest possible route for a salesman to visit each city in a list only once and return to the origin city. It explains various algorithms to solve TSP, including greedy algorithm, brute force approach, nearest neighbor method, and dynamic programming. Dynamic programming has the best time complexity of O(n2*2n) compared to O(n!) for brute force approach. The document also provides examples of real-life applications of TSP in logistics, manufacturing, network design, education, military, and airline scheduling.

Uploaded by

Shreyansh Vyas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Optimization Report

The document discusses the traveling salesman problem (TSP) in optimization. TSP aims to find the shortest possible route for a salesman to visit each city in a list only once and return to the origin city. It explains various algorithms to solve TSP, including greedy algorithm, brute force approach, nearest neighbor method, and dynamic programming. Dynamic programming has the best time complexity of O(n2*2n) compared to O(n!) for brute force approach. The document also provides examples of real-life applications of TSP in logistics, manufacturing, network design, education, military, and airline scheduling.

Uploaded by

Shreyansh Vyas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Traveling Salesman Problem

Optimization IE402

Professor
Prof. Manoj Raut

Made by
Shreyansh Vyas - 202101022
Lav Chaudhari - 202101135
INTRODUCTION
In today’s world, everyone wishes not only to complete the work but to complete the work
in minimum amount of time and with minimum resources.For example: A truck delivering goods
to various shops or a postman deliv-ering posts to various homes. The truck driver wishes to
spend less on petro land the same applies for the postman.
So we will discuss this problem and the possible solutions to it and which solution is better.
The problem is called ’The travelling salesman problem’.

EXPLANATION OF PROBLEM
The Travelling Salesman Problem (also known as Travelling SalespersonProblem or TSP)
is a renowned NP-hard problem as no ‘quick’ solution has been found till now.
The travelling salesman problem is about starting from a point and passing through all the
points (destinations) exactly once and returning back to the starting point by covering the
minimum distance.
The Travelling Salesman Problem is a problem aimed at minimising the amount of energy
expenditure. In this problem, there are a set of nodes(or cities), and a salesperson, starting from
a city (say hometown), travels through each one of them exactly once to advertise his product
and return to his hometown in the end. The salesman completes the job by covering the least
distance to stay economical.
So, one has the adjacency matrix of a particular quantity between the pairs of cities (or
nodes) that could have everything that has to be minimised. The adjacency matrix may contain
the cost of travelling between all the possible pairs of cities, the distance between every pair of
cities, or any such constraint.

Real Life problem


The TSP is a problem in which we will be searching for the minima of the function
provided. So, we can say that it is a problem in combinatorial optimization.
This problem has many real-life applications. It finds applications in the scenarios involving
routing, planning, logistics, scheduling, etc.

1. Logistics: TSP can be used to optimise the route of delivery vans and calculate the shortest
route for delivery.

2. Manufacturing: TSP can be used to optimise the route for an assembly line, thus reducing
production costs.

3. Network Design: TSP can be used to design the layout of a computer network by
optimising the route of the cables.

4. Education: TSP can be used to plan the most efficient route for a school bus to pick up and
drop off students.
5. Military Applications: TSP can be used to identify the optimal route for an army to take in
order to attack a particular target.

6.GPS System: The GPS is an application to the TSP. Google Maps would provide the
traveller with the shortest possible route to reach the destination.It re-routes to the best way if
the traveller changes his mind.

7.Airline crew scheduling: Airlines also assign rights to the crew members in a way that
they return to their hometowns.

8.Routing long-distance trains: Long-distance trains are routed in the bestway to conserve
fuel and energy.

SOLUTIONS
● Let the hometown of the salesman be node 1
● Let the adjacency matrix shown be the cost required for travelling from one node to
another.
● In the adjacency matrix, the column numbers determine the start point o the salesman at
a particular instance & the row numbers represent the final point of the salesman with
that traversal

The four algorithms that will be talked about here are:


1) Greedy algorithm
2) Brute Force Approach or Naive Approach
3) The Nearest Neighbour Method
4) Dynamic Programming
There are various approaches and algorithms to solve the Travelling Salesman Problem.

1) Greedy algorithm
❖ One approach is the use of Greedy Algorithm. As per the Greedy Algorithm, the
salesman initially goes to the point which consumes the least energy.
❖ So, as per the above example, the salesman will go to the second city first. Then, the
algorithm will again search for the best location. Thus, the salesman will go to city 4.
❖ Here, the algorithm won’t allow the salesman to return to the first city,though it is cheaper
than travelling to the fourth city because doing so will complete the loop without covering
all the cities, leading to an overall in-crease in the cost of covering all the cities just once.
With the use of the Greedy Algorithm.
❖ The path of traversal would be:1→2→4→3 →1.
❖ The cost calculated on the basis of the above traversal would be 10 +10 +
20 + 15 which equals 55.
❖ The answer obtained based on the Greedy Algorithm is correct but we can’t comment on
the optimization of this solution.
❖ So, it can be concluded that this algorithm is unconcerned with whether the most
excellent outcome at the moment will produce the final best result.
❖ The time complexity while using Greedy algorithm is O(n2*log2(n)).

2) Brute Force Approach or Naive Approach:


❖ Another such approach is Brute Force Approach or Naive Approach. This Approach lists
down all the possible paths. On calculating out the cost for each path, this approach
provides us with the most optimised path out of all the possible paths.
❖ For the above given 4 node TSP:
❖ It can be observed that the most optimal path is 1→3→4→2→1.
❖ The cost for this path is 15 + 5 + 10 + 5 which equals 35.
❖ This solution is not at all optimised as the approach will check each and every traversal
completely calculating the cost, thus increasing the time complexity.
❖ The time complexity while using Brute Force Approach or Naive Approaches O(n!).
❖ On generalising, or n nodes, there is a total o (n-1)! possible paths.So, calculating the
cost for each path will give the time complexity O(n!) which equals O(nn).
❖ This obtained time complexity is the biggest time complexity one can ever get. So, this is
the least optimised solution for the Travelling SalesmanProblem.

3) Nearest Neighbour Method


❖ One can also use the Nearest Neighbour Method to solve the TravellingSalesman
Problem.
❖ In this method, the salesman will travel from the city where he is resting currently to the
city which is at his nearest distance. The salesman continues this traversal until all the
cities are not visited.

4) Dynamic Programming
❖ The most efficient method to solve the TSP is Dynamic Programming.
❖ This method gives the guaranteed solution. Though the time complexity for solving the
TSP remains exponential, it reduces the time complexity as compared to other
methods.[3]
❖ In this method, the problem is solved in a Bottom-up approach. TheDynamic
Programming is beneficial:
❖ only when the problem is getting divided into smaller sub-problems (the solution to the
problem is obtained by combining the solutions of the sub-problems in which it is
divided)
❖ there is repetition/overlapping in the sub-problems (the benefit of this is that we can
once store the value o the repetitive portion and use it as and when required)
❖ The time complexity while using Dynamic Programming is O(n2*2n).
❖ So, the best solution after taking into account both the results and time complexity turns
out to be Dynamic Programming.

❖ The method which would definitely obtain the optimal solution of TSPis the method of
exhaustive enumeration and evaluation.
Solutions:
1) Hybrid Genetic Algorithm
2) Dynamic Programming
3) Greedy Algorithm
4) Brute force method/ Naive method
5) The Nearest Neighbour Method
The answer obtained when the problem is solved using the Greedy algorithm is inaccurate, so it
is not the most optimal solution. The time complexity for solving the travelling salesman problem
using Dynamic Programming is exponential, i.e., O(n2*2n), but still it is less than O(n!), which is
the time complexity of Brute Force Approach.

Code in Dynamic Programming:

#include <iostream>

using namespace std;

int maximum = 1000000; // Here we have assumed a maximum value to prevent overflow in
calculating the minimum cost

int steps [24][24];


int cache [24][1 << (24)];

int solve (int k, int num, int box)


{
// This if condition is for the base case
// When only 1st bit and kth bit are set in our box, it implies that we have visited all the other
nodes before
if (box == ((1 << k) | 3))
return steps [1][k];

if (cache [k][box] != 0)
return cache [k][box];

int answer = maximum; // The minimum cost for traversing all the nodes

/* In order to find the minimum cost, we have to traverse all the p nodes in box and end our
path at kth node.
Hence, with the help of dynamic programming, we are recursively calling solve function to
calculate cost of traversing
all nodes in box except k. Then we will traverse back from node p to k by taking the path
that has minimum cost of all
the available paths.
*/

for (int p = 1; p <= num ; p++)


if ((box & (1 << p)) && p != k && p != 1)
answer = min(answer, solve(p, num, box & (~(1 << k))) + steps [p][k]);

return cache [k][box] = answer;


}
// This is the driver code to find minimum cost using the above defined solve function
int main()
{
int num, x, y;

cout << "Enter the no. nodes : ";


cin >> num;
cout << endl;

cout << "Now let's make a matrix of cost of going from one node to another node" << endl <<
endl;

// steps [x][y] represents the minimum steps or cost required to go from a node x to node y

for (x = 0; x < num+1; x++)


{
for (y = 0; y < num+1; y++)
{
if (x == y || x == 0 || y==0)
{
steps [x][y] = 0;
continue;
}

cout << "Enter the cost of going from node " << x << " to node " << y << " : ";
cin >> steps [x][y];
cout << endl;
}
}

cout << "The matrix of cost that you have entered is as follows : " << endl << endl;
cout << " ";

for (x = 1; x < num+1; x++)


cout << x << "\t";
cout << endl << endl;

for (x = 1; x < num+1; x++)


{
cout << x << " ";

for (y = 1; y < num+1; y++)


{
cout << steps[x][y] << "\t";
}

cout << endl << endl;


}

int sol = maximum;

for (int q = 1; q <= num; q++)


/*
Here we are starting from node 1 and will keep traversing upto q.
After reaching at q, we will traverse back to node 1 by following the path that has
minimum cost
of all available paths.
*/
sol = min(sol, solve(q, num, (1 << (num + 1)) - 1) + steps [q][1]);

cout << "The minimum cost/steps required to traverse through all the nodes = " << sol <<
endl << endl;

return 0;
}

Output:
References
[1] In: (). url:
https://aip.scitation.org/doi/pdf/10.1063/1.4976899#:~:text=The%20traveling%20salesman%20p
roblem%20.
[2] In: ().url:
https://www.tutorialspoint.com/design_and_analysis_of_algorithms/design_and_analysis_of_alg
orithms_travelling_salesman_problem.htm.
[3] In: (). url: https://en.wikipedia.org/wiki/Dynamic_programming.

You might also like