Travelling salesman with repeat nodes dynamic weights
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
The Travelling Salesman Problem (TSP) is a well-known optimization problem in computer science and operations research. It involves finding the shortest possible route that allows a salesman to visit each city once and return to the origin city. This classic version of the problem assumes that each city is visited exactly once and that the weights (distances between cities) are constant. However, real-world scenarios often require dealing with repeat visits to nodes and dynamic weights that can change over time or based on certain conditions.
Problem Description
In the Travelling Salesman Problem with repeat nodes and dynamic weights, the salesman may visit some locations multiple times, and the cost (weight) of traveling between nodes can vary. This adds complexity to the problem, making it more challenging to find the optimal solution.
Key Challenges
- Repeat Nodes: • The need to visit certain nodes multiple times, perhaps due to restocking, customer requirements, or operational constraints.
- Dynamic Weights: • Weights can change due to factors like traffic conditions, time of day, or other temporal variables.
The objective is to minimize the total cost or travel time while adhering to the constraints of repeat visits and accommodating the dynamic nature of weights.
Technical Explanation
Mathematical Formulation
Let's formalize the problem using mathematical notation. Let be a graph where is a set of vertices (nodes) and is a set of edges (paths between nodes). Each edge has a weight that is a function of time or other variables, representing the dynamic nature of travel costs.
• Objective: Minimize , where is a decision variable that equals 1 if the edge is included in the tour, and 0 otherwise. • Constraints: • Each node must be visited at least once, with some nodes visited multiple times as needed. • The solution must form a valid cycle, starting and ending at the same node.
Dynamic Programming Approach
To solve this variation of TSP, one could use a dynamic programming approach or heuristic methods that accommodate repeat visits and dynamic weights. Here is a brief overview of a dynamic programming strategy:
- State Representation: • A state can be represented as , where is a subset of nodes visited, and is the current node.
- Recurrence Relation: • The recurrence relation takes into account both the inclusion of repeat nodes and dynamic weights:
- Initialization: • for the starting node.
- Goal: • Compute the minimum cost path that touches all required nodes, considering dynamic weights for each transition.
Example Scenario
Consider a network of delivery points spread across a city, with some points requiring multiple visits due to high demand. The weights are determined by real-time traffic data. A naive approach cannot efficiently calculate the optimal path; sophisticated algorithms that consider time-varying weights become essential.
Table: Summary of Key Points
| Aspect | Classical TSP | TSP with Repeat Nodes & Dynamic Weights |
| Objective | Shortest Hamiltonian cycle | Minimize cost with repeats and dynamic costs |
| Node Visits | Each node visited once | Some nodes visited multiple times |
| Weights | Static | Dynamic/Variable |
| Complexity | NP-hard | More complex due to added constraints |
| Approaches | Heuristics, DP, Branch & Bound | Heuristics, DP with dynamic considerations |
Practical Applications
- Logistics and Supply Chain Management: Efficient routing with multiple stops and variable delivery times.
- Ride-sharing & Vehicle Routing: Adapting to dynamic traffic conditions and varying customer requests.
- Drone Delivery: Multiple visits to charging stations with energy-based dynamic weights.
Conclusion
The Travelling Salesman Problem with repeat nodes and dynamic weights expands the classical problem into more intricate and realistic domains. This variation is crucial for applications where routes and costs are influenced by temporal and repeat visit considerations. Solutions often necessitate advanced algorithmic strategies that leverages dynamic programming and real-time data integration to address NP-hardness alongside the added complexity.
Related reading
- Traversal of an n-dimensional space
- Traversal of cyclic directed graph
- Traverse a list in reverse order in Python
- Traverse a list in reverse order in Python
- Traverse Matrix in Diagonal strips
- Traversing a complete binary min heap
- Tricks for improving iPhone UITableView scrolling performance?
- Tricks to make an AWS spot instance persistent?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.