Trains
Solution
This is an undirected weighted graph problem.
My basic idea is to use Dijkstra's algorithm to find the shortest paths.
-
Find shortest path for each package's start to destination.
-
Find a train with enough capacity at the start/current station for each package.
- If there isn't one, find the closest train with enough capacity.
- Move trains to the start stations.
-
For each train now at the start stations, pick up parcel and follow shortest path towards destination and drop parcel off at the last station.
Note
This is not an optimal solution.
References
-
An Introduction to Dijkstra’s Algorithm: Theory and Python Implementation
-
Dijkstra's Shortest Path Algorithm - A Detailed and Visual Introduction