Management Science 461 Lecture 2b – Shortest Paths September 16, 2008 Graph Theory Branch of mathematics “Graph” has a very specific definition: Collection of objects Collection of relationships between objects Both collections can have associated data (costs, weights) 2 Physical Abstraction Euler and the Königsberg Bridges - 1736 3 Shortest Path Problems Find the shortest (distance, time, cost) path between two nodes (e.g. 15) 2 5 8 5 5 1 Arc = Edge = Link 3 2 Route = Path 9 3 4 Node = Vertex Tour = Circuit = Cycle 4 4 Algebraic formulation 1 if the edge connecting node i to j is selected xij 0 otherwise 2 5 8 5 5 1 3 2 9 3 4 minimize 8 x12 2 x13 5 x32 5 x23 3x24 3x42 4 x34 4 x43 5 x25 9 x45 4 5 Flow and Integrality Constraints subject to x12 + x13 = 1 x12 + x32 + x42 = x23 + x24 + x25 x13 + x23 + x43 = x32 + x34 x34 + x24 = x43 + x42 + x45 x25 + x45 = 1 2 xij = 0 or 1 for all i, j (node 1) (node 2) (node 3) (node 4) (node 5) 5 1 3 4 6 Rearranging, we get… Flow in = flow out subject to flow in – flow out = 0 - x12 - x13 = -1 x12 + x32 + x42 - x23 - x24 - x25 = 0 x13 + x23 + x43 - x32 - x34 = 0 x34 + x24 - x43 - x42 - x45 = 0 x25 + x45 = 1 2 xij = 0 or 1 for all i, j (node 1) (node 2) (node 3) (node 4) (node 5) 5 Do these -1, 0, 1 values look familiar? 1 3 4 7 Shortest Path Problems Solve using Excel’s Solver However, a network with several hundred nodes would be out of reach, even for Premium Solver e.g. Edmonton Efficient algorithms need to be used – like Dijkstra’s algorithm 8 Dijkstra’s algorithm “Label-setting” algorithm At each node, keep track of minimum distance from origin to the node, and how we got there Very fast – polynomial time algorithm Time to solve increases polynomially with problem size (not exponential) 9 Dijkstra’s Algorithm 2 5 8 5 5 1 3 9 2 3 4 4 10 Step 0 – Place Labels 2 Dist: Pred: 2 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: Pred: 3 3 4 4 Dist: Pred: 4 11 Step 1 – Choose Minimum Label 2 Dist: Pred: 2 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: Pred: 3 3 4 4 Dist: Pred: 4 12 Step 2 – Update Adjacent Labels 2 Dist: 8 Pred: 1 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: Pred: 4 13 Step 2b – Mark Node As Optimal 2 Dist: 8 Pred: 1 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: Pred: 4 14 Step 3 – Choose Next Min Dist 2 Dist: 8 Pred: 1 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: Pred: 4 15 Step 4 – Update Adjacent Labels 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 16 Step 4b – Mark Node As Optimal 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 17 Step 5 – Choose Next Min Dist 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 18 Step 6 – Update Adjacent Labels 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 15 Pred: 4 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 19 Step 6b – Mark Node As Optimal 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 15 Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 20 Step 7 – Choose Next Min Dist 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 15 Pred: 5 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 21 Step 8 – Update Adjacent Labels 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 12 Pred: 2 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 22 Step 8b – Mark Node As Optimal 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 12 Pred: 2 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 23 Step 9 – Choose Next Min Dist 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 12 Pred: 2 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 24 Step 10 – Update Adjacent Labels 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 12 Pred: 2 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 25 Step 10b – Mark Node As Optimal 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 12 Pred: 2 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 26 Final Solution – Min Dist Tree 2 Dist: 7 Pred: 3 5 8 Dist: 0 Pred: 1 Dist: 12 Pred: 2 5 5 1 3 9 2 Dist: 2 Pred: 1 3 4 4 Dist: 6 Pred: 3 27