# L17_10 - Dijkstra’s algorithm for the shortest path...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Dijkstra’s algorithm for the shortest path problem We label all the nodes with temporary labels representing the currently found distance to the node from the root node 1 (initially, node 1 is given the label 0 and the rest of the nodes are assigned the label ∞). At each step, a minimum label is made permanent, the arcs from the corresponding node are scanned and the temporary labels are updated. The algorithm terminates when all labels are permanent. 2/29 Initialize the distances and the list... d (2) = pred (2) = ∞ d (4) = pred (4) = ∞ d (1) = 0∗ pred (1) = 0  -4   7  @ S 6 S2 2 @  S @  @ S    w S d @2 1 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S  @ S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞ d (5) = pred (5) = ∞ d = [0∗ , ∞, ∞, ∞, ∞, ∞] LIST = {1} 3/29 Find the node i from LIST with minimum d (i ): i = 1. d (2) = pred (2) = ∞ d (4) = pred (4) = ∞ d (1) = 0∗ pred (1) = 0  -4   7  @ S 6 S2 2 @  S @  @ S    w S d @2 1 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S  @ S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞ d (5) = pred (5) = ∞ d = [0∗ , ∞, ∞, ∞, ∞, ∞] LIST = {1} 4/29 Scan the arcs out of i = 1, and update d , pred , and LIST . d (2) = pred (2) = ∞2 1 d (4) = pred (4) = ∞ d (1) = 0∗ pred (1) = 0  -4   7  @ S 6 S2 2 @  S @  @ S    w S d @2 1 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S  @ S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞4 1 d (5) = pred (5) = ∞ d = [0∗ , 2, 4, ∞, ∞, ∞] LIST = { 1, 2, 3} 5/29 Find the node i from LIST with minimum d (i ), make its label permanent: i = 2. d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞ d (1) = 0∗ pred (1) = 0  -4   7  @ S 6 S2 2 @  S @  @ S    w S d @2 1 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S  @ S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞4 1 d (5) = pred (5) = ∞ d = [0∗ , 2∗ , 4, ∞, ∞, ∞] LIST = { 1, 2, 3} 6/29 Scan the arcs out of i = 2, and update d , pred , and LIST . d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞6 2 d (1) = 0∗ pred (1) = 0  -4   7  S @ 2 6 S2 @  S @  S  @   w S d (6) 1 3 @2 1 6 pred (6) = @   = 7  S4 @ 2 S  @ S @  S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞ 43 12 d (5) = pred (5) = ∞4 2 d = [0∗ , 2∗ , 3, 6, 4, ∞] LIST = { 1, 2, 3, 4, 5} 7/29 Find the node i from LIST with minimum d (i ), make its label permanent: i = 3. d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞6 2 d (1) = 0∗ pred (1) = 0  -4   7  S @ 2 6 S2 @  S @  S  @   w S d 1 3 @2 1 6 pred (6) = (6) @   = 7  S4 @ 2 S  @ S @  S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞4 2 d = [0∗ , 2∗ , 3∗ , 6, 4, ∞] LIST = { 1, 2, 3, 4, 5} 8/29 Scan the arcs out of i = 3, and update d , pred , and LIST . d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞6 2 d (1) = 0∗ pred (1) = 0  -4   7  S @ 2 6 S2 @  S @  S  @   w S d 1 3 @2 1 6 pred (6) = (6) @   = 7  S4 2 @ S  @ S @  S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞4 2 d = [0∗ , 2∗ , 3∗ , 6, 4, ∞] LIST = { 1, 2, 3, 4, 5} 9/29 Find the node i from LIST with minimum d (i ), make its label permanent: i = 5. d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞6 2 d (1) = 0∗ pred (1) = 0  -4   7  S @ 2 6 S2 @  S @  S  @   w S d 1 3 @2 1 6 pred (6) = (6) @   = 7  S4 @ 2 S  @ S @  S  ?  R @ w S 3 -5 3    2 4 ∞ d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞ 4∗ 2 d = [0∗ , 2∗ , 3∗ , 6, 4∗ , ∞] LIST = { 1, 2, 3, 4, 5} 10/29 Scan the arcs out of i = 5, and update d , pred , and LIST . d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞6 2 d (1) = 0∗ pred (1) = 0  -4   7  @ S 2 6 S2 @  @ S  @ S    w S d @2 1 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S @  S  ?  R @ w S 3 -5 3    2 4 ∞6 5 d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞ 4∗ 2 d = [0∗ , 2∗ , 3∗ , 6, 4∗ , 6] LIST = { 1, 2, 3, 4, 5, 6} 11/29 Find the node i from LIST with minimum d (i ), make its label permanent: i = 4. d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞ 6∗ 2 d (1) = 0∗ pred (1) = 0  -4   7  @ S 2 6 S2 @  @ S  @ S    w S d @2 1 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S @  S  ?  R @ w S 3 -5 3    2 4 ∞6 5 d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞ 4∗ 2 d = [0∗ , 2∗ , 3∗ , 6∗ , 4∗ , 6] LIST = { 1, 2, 3, 4, 5, 6} 12/29 Scan the arcs out of i = 4, and update d , pred , and LIST . d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞ 6∗ 2 d (1) = 0∗ pred (1) = 0  -4   7  @ S 2 6 S2 @  @ S  @ S    w S d 1 @2 3 1 6 pred (6) = (6) @   = 7  S4 @ 2 S @  S @  S  ?  R @ w S 3 -5 3    2 4 ∞6 5 d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞ 4∗ 2 d = [0∗ , 2∗ , 3∗ , 6∗ , 4∗ , 6] LIST = { 1, 2, 3, 4, 5, 6} 13/29 Find the node i from LIST with minimum d (i ), make its label permanent: i = 6. d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞ 6∗ 2 d (1) = 0∗ pred (1) = 0  -4   7  S @ 2 6 S2 @  @ S  @ S    w S d 1 3 @2 1 6 pred (6) = (6) @   = 7  S4 2 @ S @  S @  S  ?  R @ w S 3 -5 3    2 4 ∞ 6∗ 5 d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞ 4∗ 2 d = [0∗ , 2∗ , 3∗ , 6∗ , 4∗ , 6∗ ] LIST = { 1, 2, 3, 4, 5, 6} 14/29 All labels are permanent, the LIST is empty. Terminate. d (2) = pred (2) = ∞ 2∗ 1 d (4) = pred (4) = ∞ 6∗ 2 d (1) = 0∗ pred (1) = 0  -4   7  S @ 2 6 S2 @  @ S  @ S    w S d 1 3 @2 1 6 pred (6) = (6) @   = 7  S4 2 @ S @  S @  S  ?  R @ w S 3 -5 3    2 4 ∞ 6∗ 5 d (3) = pred (3) = ∞ 4 3∗ 12 d (5) = pred (5) = ∞ 4∗ 2 d = [0∗ , 2∗ , 3∗ , 6∗ , 4∗ , 6∗ ] LIST = { 1, 2, 3, 4, 5, 6} 15/29 The solution obtained by Dijkstra’s algorithm   7  @ 2 @ 2 4  -4    7  2 @  @   R @        1 1 @ @ @2 @ @ 6 ?   3 5 The output of Dijkstra’s algorithm provides a shortest path from node 1 to all other nodes. It provides a shortest path tree. To ﬁnd the shortest path from node j , trace back from the node to the source. 16/29 Maximum Flow Problems Many situations can be modeled by a network in which the arcs may be thought of as having a capacity that limits the quantity of a product that may be shipped through the arc. In these situations, it is often desired to transport the maximum amount of ﬂow from a starting point (called the source) to a terminal point (called the sink). Such problems are called maximum ﬂow problems. 17/29 Maximum Flow Problems Example Sunco Oil wants to ship the maximum possible amount of oil (per hour) via pipeline from node so to node si as shown in the ﬁgure. 4  -3  1     U 2- 1 3- 2 2 - si so     Y 3 a0 The various arcs represent pipelines of diﬀerent diameters. The maximum number of barrels of oil that can be pumped through each arc (also called the arc capacity) is also shown in the ﬁgure. Here a0 is an artiﬁcial arc from sink to source, which is used in an LP formulation of this problem. 18/29 Maximum Flow Problems To formulate this problem as an LP deﬁne the decision variable as xij = Millions of barrels of oil per hour that will pass through arc (i,j) of pipeline For a ﬂow to be feasible it needs to be in the following range: 0 ≤ ﬂow through each arc ≤ arc capacity and Flow into node i = Flow out of node i (the conservation-of-ﬂow constraint). 19/29 Maximum Flow Problems Let x0 be the ﬂow through the artiﬁcial arc. The conservation of ﬂow implies that x0 = total amount of oil entering the sink. Thus, Sunco’s goal is to maximize x0 . 4  -3  1     U 2- 1 3- 2 2 - si so     Y 3 a0 20/29 Maximum Flow Problems We obtain the following formulation: max z = x0 s.t. xso ,1 ≤ 2 xso ,2 ≤ 3 x12 ≤ 3 x2,si ≤ 2 x13 ≤ 4 x3,si ≤ 1 x0 = xso ,1 + xso ,2 xso ,1 = x12 + x13 xso ,2 + x12 = x2,si x13 = x3,si x3,si + x2,si = x0 xij ≥ 0 for all i , j 4  -3  1     U 2- 1 3- 2 2 - si so     Y 3 a0 (Arc Capacity constraints) (Node so ﬂow constraints) (Node 1 ﬂow constraints) (Node 2 ﬂow constraints) (Node 3 ﬂow constraints) (Node si ﬂow constraints) 21/29 Maximum Flow Problems The optimal solution to this LP is xso ,1 = 2, x13 = 1, x12 = 1, xso ,2 = 1, x3,si = 1, x2,si = 2, x0 = 3 with z = 3: (1)4  -3  (1)1     U so (2)2 1 (1)3 2 (2)2 si     Y (1)3 a0 (3) 22/29 Maximum Flow Problems Denote by: fij = ﬂow on ark (i , j ) cij = capacity of ark (i , j ) I = the set of arcs whose ﬂow can be increased R = the set of arcs whose ﬂow can be reduced   i (fij )cij j   If fij < cij then (i , j ) belongs to I If fij > 0 then (i , j ) belongs to R If 0 < fij < cij then (i , j ) belongs to both I and R 23/29 The labeling procedure 1. Label the source 2. Perform the following labeling process: (a) Label an arc (x , y ) as a forward arc if x was labeled, y was unlabeled and (x , y ) is in I . (b) Label an arc (y , x ) as a backward arc if x was labeled, y was unlabeled and (y , x ) is in R . In both cases, label node y . 3. Continue the labeling process until sink has been labeled or until no more vertices can be labeled. 24/29 The labeling procedure i n- labeled node i n- unlabeled node (1)  -3  - - forward arc - - backward arc (2)  -3  (0)4 (0)1 (0)4 (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 (3) (0)4  -3  (0)1 (4) (0)4  -3  (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 25/29 The labeling procedure i n- labeled node i n- unlabeled node (1)  -3  - - forward arc - - backward arc (2)  -3  (0)4 (0)1 (0)4 (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 (3) (0)4  -3  (0)1 (4) (0)4  -3  (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 25/29 The labeling procedure i n- labeled node i n- unlabeled node (1)  -3  - - forward arc - - backward arc (2)  -3  (0)4 (0)1 (0)4 (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 (3) (0)4  -3  (0)1 (4) (0)4  -3  (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 25/29 The labeling procedure i n- labeled node i n- unlabeled node (1)  -3  - - forward arc - - backward arc (2)  -3  (0)4 (0)1 (0)4 (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 (3) (0)4  -3  (0)1 (4) (0)4  -3  (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3     U so (2)2 1 (2)3 2 (2)2 si     (0)3 25/29 Ford-Fulkerson Algorithm If the sink node cannot be labeled, we have an optimal solution If the sink node was labeled, there exist a path from source to sink consisting of arcs each of which was labeled as either forward or backward. For such a path we ﬁnd the maximum decrease d that would be feasible for all backward arcs: d = min{fij : (i , j ) − backward arc} we ﬁnd the maximum increase e that would be feasible for all forward arcs: e = min{(cij − fij ) : (i , j ) − forward arc} Let ∆ = min{d , e }. Then, in order to increase the total ﬂow from source to sink by ∆, we increase the ﬂow for all forward arcs in the path by ∆ and decrease the ﬂow for all backward arcs by ∆. 26/29 Ford-Fulkerson Algorithm 1. Find a feasible ﬂow (say, set each arc’s ﬂow = 0). 2. Using the labeling procedure, try to label the sink. If the sink cannot be labeled, then the current feasible ﬂow is a maximum ﬂow; if the sink can be labeled - go to step 3. 3. Adjust the feasible ﬂow and increase the ﬂow from source to sink. Go to step 2. 27/29 Ford-Fulkerson Algorithm  -3  (0)4 (0)1     U so (2)2 1 (2)3 2 (2)2 si     (0)3 We label sink by so − 2 − 1 − 3 − si . d = min{fij : (i , j ) − backward arc} = 2 e = min{(cij − fij ) : (i , j ) − forward arc} = 1 Thus, we add 1 unit of ﬂow. 28/29 Ford-Fulkerson Algorithm The resulting ﬂow is optimal: (1)4  -3  (1)1     U so (2)2 1 (1)3 2 (2)2 si     (1)3 29/29 ...
View Full Document

## This note was uploaded on 12/14/2010 for the course ESI 6314 taught by Professor Vladimirlboginski during the Fall '09 term at University of Florida.

Ask a homework question - tutors are online