Professional Documents
Culture Documents
DM Project 6
DM Project 6
PROJECT
July 9, 2022
Professors:
Prof. Manish Gupta & Prof. Manoj Raut
Made by:
Nishith Parekh(202101449)
Abhinav Agarwal(202101040)
Priya Tank(202101463)
Dhruv Lad(202101497)
Keyur Govrani(202101498)
Vraj Patel(202101060)
1
1 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 petrol
and the same applies for the postman.
→So we will discuss about this problem and the possible solutions to it
and which solution is better. The problem is called ’The travelling salesman
problem’.
2 EXPLANATION OF PROBLEM
→The Travelling Salesman Problem (also known as Travelling Salesperson
Problem 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 pass-
ing through all the points (destinations) exactly once and returning back to
the starting point by covering minimum distance.
→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 mini-
mized. The adjacency matrix may contain the cost of traveling between all
the possible pairs of cities, the distance between every pair of cities, or any
such constraint.
→ Interaction of TSP with some real-life problems:[1]
→GPS System: The GPS is an application of the TSP. Google Maps would
provide the traveler with the shortest possible route to reach the destination.
It re-routes to the best way if the traveler changes his mind.
→Airline crew scheduling: Airlines also assign flights to the crew members
in a way that they return to their hometowns.
→In this way, TSP finds its application in various discrete fields.
3 SOLUTIONS
[2]
→Let the hometown of the salesman be node 1:
→ Let the adjacency matrix shown be the cost required for traveling from
one node to another.
→In the adjacency matrix, the column numbers determine the start point of
the salesman at a particular instance & the row numbers represent the final
point of the salesman with that traversal.
1) Greedy algorithm
2) Brute Force Approach or Naive Approach
3) Dynamic Programming
→There are various approaches and algorithms to solve the Travelling Sales-
man Problem.
→One approach is the use of Greedy Algorithm. As per the Greedy Al-
gorithm, 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 time complexity while using Greedy algorithm is O(n2 *log2 n).
→This solution is not at all optimized one 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 Approach
is O(n!).
→This obtained time complexity is the biggest time complexity one can
ever get. So, this is the least optimized solution for the Travelling Salesman
Problem.
→One can also use the Nearest Neighbour Method to solve the Travelling
Salesman Problem.
→In this method, the salesman will travel from the city where he is rest-
ing currently to the city which is at his nearest distance. The salesman
continues this traversal until all the cities are not visited.
→only when the problem is getting divided into smaller sub-problems (the
solution of the problem is obtained by combining the solutions of the sub-
problems in which it is divided)
→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 TSP
is the method of exhaustive enumeration and evaluation.
→Solutions:
→The answer obtained when the problem is solved using Greedy algorithm
is not so accurate 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 lesser than O(n!) which is the time
complexity for Brute Force Approach.
#include <iostream>
if (cache [k][box] != 0)
return cache [k][box];
int answer = maximum; // The minimum cost for traversing all the nodes
int main()
{
int num, x, y;
cout << "Now let’s make a matrix of cost of going from one node
to another node" << endl << endl;
cout <<"Enter the cost of going from node "<< x << " to node "<<y<<" : ";
cin >> steps [x][y];
cout << endl;
}
}
References
[1] In: (). url: https : / / aip . scitation . org / doi / pdf / 10 . 1063 / 1 .
4976899#:~:text=The%20traveling%20salesman%20problem%20.
[2] In: (). url: https://www.tutorialspoint.com/design_and_analysis_
of_algorithms/design_and_analysis_of_algorithms_travelling_
salesman_problem.htm.
[3] In: (). url: https://en.wikipedia.org/wiki/Dynamic_programming.