320 likes | 460 Views
Multi-Source Shortest Paths. T. Patrick Bailey CSC 5408 Graph Theory 4/28/2008. Inspiration. Using the public transit system in the Denver metro area (RTD) I discovered a problem.
E N D
Multi-Source Shortest Paths T. Patrick Bailey CSC 5408 Graph Theory 4/28/2008
Inspiration Using the public transit system in the Denver metro area (RTD) I discovered a problem. The web based tools put in place to assist patrons in finding the shortest path to their destination is limited. In its current implementation it only can search for a shortest path given a single start time or a single end time.
Inspiration (cont) I and many other professional workers are not bound by a tight work schedule, our work hours can “float”. Given this situation a more ideal search would be to find the shortest path over a given time (from 7:00AM to 9:00 AM) rather then from a fixed time. This search would give us the shortest trip time to our destination.
The Graph To help understand what a shortest path is in a mass Transit Graph we need to understand what a node in such a graph represents and how the entire graph is formed.
First we need to convert routes into individual paths. Here is an example of a route where each node representing a location (a bus stop) B D E C A Here we can see a bus route that goes from location A to B, C, D, and finally E. But this graph represents a route path. What we need is a graph representing each unique bus path over time.
B D E C A This Route Path needs to be converted into individual bus paths. B 10:30AM D 11:00 AM 10:00 AM E 11:45 AM C 10:45 AM A 10:00 AM B 1:30PM D 2:00 PM 1:00 PM E 2:45 PM C 1:45 PM A 1:00 PM
We turn the entire transit system into individual bus paths. The nodes in this graph represent a time and location
Then connect them up (Details Beyond the scope of this talk)
Weights are assigned to each edge (The time difference between nodes) 30 15 15 45 B 10:30AM D 11:00 AM 10:00 AM E 11:45 AM 75 C 10:45 AM A 10:00 AM 30 15 45 15 B 11:30 AM D 12:00 PM 11:00 AM E 12:45 PM C 11:45 AM A 1:00 PM
We now have a graphical representation of the transit system with weights. “The Transit Graph” Now what do we do with it?
First we Find Nodes on the Transit Graph which are near our start location Ex. within 1 mile from 7:00 AM – 9:00 AM These are our Source Nodes As a commuter we want to find the shortest path (time) over some range of time. To Do This
Next we Find Nodes on the Transit Graph which are near our destinationWithin 1 mile from 7:00 AM – 11:00 AM
So here is the problem. How do we find the shortest path from multiple Source Nodes to multiple Destination Nodes Destination Nodes Source Nodes
Several Types of Solutions “Single Source Shortest Path” (SSSP) - This type of solution can only find the shortest path from a single source. We can use it though, by simply running it once per source and comparing the results to each other and choosing the best result. “All Pairs Shortest Paths” (APSP) - This type of solution gives us more then what we need. As it gives the shortest path between all pairs of vertices in a graph.
Djikstra’s Algorithm [D59] A SSSP solution Type - “Single Source Shortest Path” Runtime - O(|V|2) (converted to a MSSP O(|V|3)) Input - A weighted connected graph G whose edge weights are non-negative. Output - A spanning Tree of G whose root is your source node S. Any path on this tree from S to any other node is a shortest path to that node.
Djikstra’s Algorithm Example Here is our weighted Graph with no negative weight edges First we find all frontier edges Then we again find all frontier edges We keep repeating this process until we have a Spanning Tree Then we select the edge with the smallest overall weight and add that edge and vertice to our spanning Tree S
An IdeaConverting our MSSP to a SSSP In my bus problem all edge weights are > 0. Therefore we can easily convert the “Multi-Source Shortest Path” to a “Single-Source Shortest Path” by linking the all source nodes to a single source node with 0 weight edges. And we can do the same for the destination node.
Turning it into a Single Source Problem (And saving us O(|V|) in runtime ) Destination Nodes Source Nodes
Advantages- Its faster It gets the fastest path without need for comparing the sets of fastest paths between node Once we find a path to our destination we can stop since we know it’s a fastest path. Disadvantages- We lose information, perhaps we want to know the fastest 10 paths. We lose that information.
“All Pairs Shortest Paths” (APSP) There are many algorithms for solving the APSP. Due to time constraint I will only show Min-Plus Product and if time allows the Technique of Repeated Squaring.
Min-Plus Product Type - “All Pairs Shortest Path” Runtime - Input - A weighted connected graph G which contains now negative weight cycles. Output - A Matrix Showing Weight of shortest path (we can store a path along the way)
Min-Plus Product First create a matrix representing the weights between edges. This graph represents Where m represents the longest path
Min-Plus Product What we need is Since the shortest path between any two vertices on graph is n-1 This runs in Since this equation needs (m-1) the prior matrix. We need each matrix along the way we need 1,2,3… n-1 For an overall runtime of
Technique of Repeated Squaring. Type - “All Pairs Shortest Path” Runtime - Input - A weighted connected graph G which contains now negative weight cycles. Output - A Matrix Showing Weight of shortest path (we can store a path along the way)
Technique of Repeated Squaring. The Min-Plus Product can be altered slightly to make it run faster. First of all all we care about is finding Second any where m > n-1 matches n-1.
Technique of Repeated Squaring. As it turns out So we can square it we can get 1, 2, 4, 8 which may in some cases be larger then n-1 but that is fine since any matrix larger then n-1 is identical to n-1.
Chan O(n3/logn) Type - “All Pairs Shortest Path” Runtime - O(n3/logn) Input - Weighted Directed Graph Output - (Still trying to figure that one out)
Bibliography: [D59] E. W. Dijkstra A Note on two Problems in Connection with Graphs. Numerical Mathematics, 1(5):269-271, 1959 [C08] Timothy M. Chan All-Pairs Shortest Paths with Real Weights in O(n3/logn) Time. Algorithmica 2(50):236-243, 2008 [CLR07] Thomas H. Cormen, Charles E. Leiserson, Ronald L Rivest, and Clifford Stein. Introduction to Algorithms 2nd Edition 2007.