Travelling Salesman
Problem
Using
Dynamic Programming
Bharati Vidyapeeth (Deemed to be University) College of Engineering,
Pune- 43
Session: 2023-24
Topic:Subject : NLDS
Travelling and DMS
Salesman Problem
Group Members Sudarshana Ma’am
Guided By Aaradhana Ma’am
Yuvraj Singh (2214110045)
Bhumika Yadav (2214110049)
INTRODUCTION
The Travelling Salesman Problem (TSP) is one of the most famous and fundamental problems in the field of
optimization and computer science. It is a combinatorial problem that can be succinctly described as follows:
Given a list of cities and the distances between each pair of cities, the task is to find the shortest possible route that
visits each city exactly once and returns to the starting city. In other words, it's about finding the most efficient way
for a salesperson to visit a set of cities and then return home while minimizing the total distance travelled.
3
Objectives of TSP
1. Minimize Total Travel Distance: to find a tour that minimizes the total
distance or cost required to visit all cities and return to the starting point.
2. Optimize Resource Utilization: By identifying the most efficient route, the
.
TSP helps optimize the allocation of resources, such as vehicles and drivers,
leading to cost savings and improved resource utilization.
3. Enhance Operational Efficiency: Contributes to operational efficiency in
various domains, such as delivery services, where finding the shortest route
improves delivery speed and customer satisfaction.
4. Route Planning and Scheduling: Crucial for route planning and
scheduling,
ensuring that routes are both efficient and feasible, especially when multiple locations need to be visited in a specific order.
5. Complex Network Design: In telecommunications and network design, it helps in designing efficient communication networks with
minimal latency or resource usage.
[Link] Reduction: By finding an optimal or near-optimal solution, it helps organizations reduce transportation costs, fuel consumption,
and vehicle wear and tear.
7. Environmental Impact: Reducing travel distances through TSP solutions can have a positive environmental impact by lowering carbon
emissions and reducing the ecological footprint of transportation operations.
4
Applications of Travelling
Salesman Problem
1. Delivery and Logistics: To optimize routes for delivery trucks,
postal services, and couriers. By finding the shortest path between
multiple stops, they can minimize fuel consumption, reduce travel
time, and increase efficiency.
2. Manufacturing: TSP is used in manufacturing processes, such as
CNC machining or 3D printing, to determine the most efficient
sequence of operations for processing multiple parts. This reduces
machine idle time and improves overall production efficiency.
3. Circuit Board Manufacturing: To optimize the order in which
components are placed on the board to minimize the length of
connecting traces. This helps reduce production costs and improve
the performance of electronic devices.
4. Vehicle Routing: TSP is applied to route planning for various
types of vehicles, including taxis, buses, and emergency services. It
ensures that vehicles can cover their service areas efficiently,
reducing travel time and costs.
. Waste Collection: Municipalities use TSP to optimize garbage and recycling collection routes. By minimizing the distance traveled
by waste collection trucks, cities can reduce fuel consumption and lower operational costs.
. Job Scheduling: Scheduling tasks or jobs in factories, hospitals, and service centers to minimize downtime and resource usage.
5
Dynamic Programming
Dynamic Programming is a technique in computer programming that helps to efficiently solve a class of problems that have
overlapping subproblems and optimal substructure property.
If any problem can be divided into subproblems, which in turn are divided into smaller subproblems, and if there are
overlapping among these subproblems, then the solutions to these subproblems can be
saved for future reference. In this way, efficiency of the CPU can be enhanced.
It works by storing the result of subproblems so that when their solutions are required,
they are at hand and we do not need to recalculate them.
This technique of storing the value of subproblems is called memoization.
Why is Dynamic Programming preferred over Greedy Algorithms?
Optimality: DP guarantees finding the optimal solution, while greedy algorithms may not.
Complex Problems: DP handles complex problems with overlapping subproblems and optimal substructure effectively.
Versatility: DP is applicable to a wide range of problems, including those where greedy strategies are inadequate
Complexity : Dynamic programming creates n.2ⁿ subproblems for n cities. Each sub-problem can be solved in linear time. Thus the
time complexity of TSP using dynamic programming would be O(n²2ⁿ). It is much less than n! but still, it is an exponent. Space
complexity is also exponential. 6
ANALYSIS AND EXPLANATION OF THE IDENTIFIED PROBLEM
Problem Statement:
Given a set of cities and the distances between each pair of cities, the
objective is to find the shortest possible route that visits each city exactly
once and returns to the starting city.
Dynamic Programming Steps:
Create a cost matrix representing distances between cities.
Initialize a memoization table with a special marker value.
Start with a base case: for each city 'i', calculate the cost of going from the
starting city to 'i' and back to the starting city.
Recursively calculate the minimum cost of visiting a subset of cities and
returning to the starting city, storing the results in the memoization table.
Use the memoization table to find the optimal tour with the minimum
cost.
Solution Extraction: Trace back through the memoization table to
reconstruct the optimal tour.
Output: The reconstructed tour is the optimal solution to the TSP.
Dynamic programming guarantees an optimal solution but can be computationally expensive for large instances of TSP
9
8
9
10
LAYOUT oF THE EXPECTED OUTPUT
Enter Total Number of Cities: [User Input] //input by the user for the total number of cities.
Enter Names of Cities: //names of the cities entered by the user
Enter the name of City 1: [City Name 1]
Enter the name of City 2: [City Name 2]
...
Enter Cost Matrix: // cost or distance between cities entered by the user
Enter cost from [City Name 1] to [City Name 2]: [Cost]
Enter cost from [City Name 1] to [City Name 3]: [Cost]
...
Entered Cost Matrix: //displayed cost matrix showing distances between cities.
[Cost Matrix Displayed]
Path: [Optimal TSP Path Displayed] //optimal TSP tour path, with city names separated by "->"
Minimum Cost: [Optimal TSP Cost] //minimum cost of the TSP tour.
11
Thank You!
Thank you !