270 likes | 288 Views
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).
E N D
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)
Physical Abstraction • Euler and the Königsberg Bridges - 1736
5 2 8 5 5 1 3 9 2 3 4 4 Shortest Path Problems • Find the shortest (distance, time, cost) path between two nodes (e.g. 15) Node = Vertex Arc = Edge = Link Route = Path Tour = Circuit = Cycle
5 2 8 5 5 1 3 9 2 3 4 4 Algebraic formulation
2 5 1 3 4 Flow and Integrality Constraints subject to x12 + x13= 1 (node 1) x12 + x32+ x42= x23 + x24+ x25 (node 2) x13 + x23+ x43= x32 + x34 (node 3) x34 + x24= x43+ x42+ x45 (node 4) x25+ x45= 1 (node 5) xij= 0 or 1 for all i, j
2 5 1 3 4 Rearranging, we get… Flow in = flow out flow in – flow out = 0 subject to - x12 - x13= -1 (node 1) x12 + x32+ x42 - x23 - x24 - x25= 0 (node 2) x13 + x23+ x43 - x32 - x34= 0 (node 3) x34 + x24 - x43 - x42 - x45= 0 (node 4) x25+ x45= 1 (node 5) xij= 0 or 1 for all i, j Do these -1, 0, 1 values look familiar?
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
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)
Dijkstra’s Algorithm 2 5 8 5 5 1 3 9 2 3 4 4
Step 0 – Place Labels Dist: Pred: 2 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: Pred: 3 4 Dist: Pred: 4
Step 1 – Choose Minimum Label Dist: Pred: 2 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: Pred: 3 4 Dist: Pred: 4
Step 2 – Update Adjacent Labels Dist: 8 Pred: 1 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: Pred: 4
Step 2b – Mark Node As Optimal Dist: 8 Pred: 1 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: Pred: 4
Step 3 – Choose Next Min Dist Dist: 8 Pred: 1 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: Pred: 4
Step 4 – Update Adjacent Labels Dist: 7 Pred: 3 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 4b – Mark Node As Optimal Dist: 7 Pred: 3 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 5 – Choose Next Min Dist Dist: 7 Pred: 3 2 Dist: Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 6 – Update Adjacent Labels Dist: 7 Pred: 3 2 Dist: 15 Pred: 4 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 6b – Mark Node As Optimal Dist: 7 Pred: 3 2 Dist: 15 Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 7 – Choose Next Min Dist Dist: 7 Pred: 3 2 Dist: 15 Pred: 5 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 8 – Update Adjacent Labels Dist: 7 Pred: 3 2 Dist: 12 Pred: 2 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 8b – Mark Node As Optimal Dist: 7 Pred: 3 2 Dist: 12 Pred: 2 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 9 – Choose Next Min Dist Dist: 7 Pred: 3 2 Dist: 12 Pred: 2 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 10 – Update Adjacent Labels Dist: 7 Pred: 3 2 Dist: 12 Pred: 2 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Step 10b – Mark Node As Optimal Dist: 7 Pred: 3 2 Dist: 12 Pred: 2 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3
Final Solution – Min Dist Tree Dist: 7 Pred: 3 2 Dist: 12 Pred: 2 5 8 Dist: 0 Pred: 1 5 5 1 3 9 2 3 4 Dist: 2 Pred: 1 4 Dist: 6 Pred: 3