Single Source Shortest Path A directed graph G = ( V, E ) and a pair of nodes s, d is given. The edges have a real-valued weight W i . This time we are looking for the weight and the shortest path from s to d . • The weight of the shortest path from s to d is called δ ( s, d ). • We still have the property that a shortest path between u and v contains shortest path between intermediate nodes. • The shortest path between s and d might not be defined if the graph contains cycles with negative weight. • A shortest path can not contain s positive weight cycle. Hence, path length is at most n − 1. SSSP 1
Shortest Path Tree A shortest path tree G ′ = ( V ′ , E ′ ) is a directed subgraph of G ( V ′ ⊂ V and E ′ ⊂ E ), such that 1. V ′ is the set of nodes reachable from s in G . 2. G ′ forms a rooted tree with root s , and 3. For all v ∈ V ′ , the unique simple path from s to v in G ′ is a shortest path from s to v in G . Shortest paths and shortest path trees are not unique! SSSP 2
Relaxation • For each vertex v ∈ V we maintain an attribute d [ v ], which is an upper bound on the weight of a shortest path from source s to v . The attribute is called shortest path estimate . • In the beginning, d [ v ] = ∞ for v � = s and d [ s ] = 0. • We also use variables π [ v ] storing the predecessor of v . • In a relaxation step we may decrease the shortest path estimate and update the π values. SSSP 3
Relaxation ( u, v, w ) If d [ v ] > d [ u ] + w [ u, v ], then d [ v ] := d [ u ] + w ( u, v ) and π [ v ] = u The path that uses u as a last edge is shorter than the one we found previously. Bellman-Ford ( G, w, s ) Initialise-Single-Source ( G, s ) for i ← 1 to | V [ G ] | − 1 do for each edge ( u, v ) ∈ E [ G ] do Relax ( u, v, w ) for each edge ( u, v ) ∈ E [ G ] do if d [ v ] > d [ u ] + w ( u, v ) then return False return True SSSP 4
Runtime and Correctness • The runtime is easy. In every iteration of the for-loop we relax every edge. We need | V | − 1 passes over all edges. This gives a runtime of O ( V E ). • First we show the following: if there are no negative-weight cycles, the algorithm computes correct shortest path weights for all vertices reachable from s . • But to do that we need a couple of other results,... Lemma 1 Let G = ( V, E ) be a weighted directed graph with source s and weight function w : E − → R , and assume that G contains no negative-weight cycle that is reachable from s . Then, after | V | − 1 iterations of the first for-loop of the Bellman-Ford, we have d [ v ] = δ ( s, v ) for all vertices v that are reachable from s . SSSP 5
Upper bound property Lemma 2 Let G = ( V, E ) be a weighted, directed graph with weight function w : E − → R , and let s ∈ V be a source vertex. Assume G is initialised as we defined. Then d [ v ] ≥ δ ( s, v ) for all v ∈ V , and this invariant is maintained over any sequence of relaxation steps. Moreover, once d [ v ] achieves its lower bound δ ( s, v ), it never changes. SSSP 6
Proof of Lemma 2 • We prove the invariant d [ v ] ≥ δ ( s, v ) by induction over the number of relaxation steps. • After the in initialisation d [ v ] ≥ δ ( s, v ) is certainly true. • For the inductive step, consider the relaxation of an edge ( u, v ). By the inductive hypothesis, d [ x ] ≥ δ ( s, x ) for all x ∈ V prior to the relaxation. • If d [ v ] changes we have d [ v ] = d [ u ] + w ( u, v ) ≥ δ ( s, u ) + w ( u, v ) ≥ δ ( s, v ) . • To see that the value of d [ v ] never changes once d [ v ] = δ ( s, v ) have a look at the above equations again. We have just shown d [ v ] ≥ δ ( s, v ). It can not increase since relaxation steps do not increase values. SSSP 7
Lemma 3: Convergence property Let G = ( V, E ) be a weighted, directed graph with weight function w : E − → R , and let s ∈ V be a source vertex. Let s = ⇒ u → v be a shortest path in G for some vertices u, v ∈ V . Suppose that G is initialised as we defined. Then, a sequence of relaxation steps that includes the call RELAX( u, v, w ) is executed on the edges of G . If 4 d [ u ] = δ ( s, u ) at any time prior to the call, then d [ v ] = δ ( s, v ) at all times after the call. SSSP 8
Proof of Lemma 3 • By the upper bound property : if d [ u ] = δ ( s, u ) at some point prior to relaxing edge ( u, v ), then this equality holds thereafter. • After relaxing edge ( u, v ) we have we have d [ v ] ≤ d [ u ] + w ( u, v ) = δ ( s, u ) + w ( u, v ) = δ ( s, v ). • The first inequality is due to the fact that, after relaxing edge ( u, v ), we have d [ v ] ≤ d [ u ] + w ( u, v ). • The last equality is due to the fact that subpath of shortest path are also shortest paths. • By the upper bound property , d [ v ] ≥ δ ( s, v ), from which we can conclude that d [ v ] = δ ( s, v ), and this equality is maintained thereafter. SSSP 9
Path-relaxation Property Lemma 4 Let G = ( V, E ) be a weighted, directed graph with weight function w : E − → R , and let s ∈ V be a source vertex. Consider any shortest path p = ( v 1 , v 2 , . . . , v k ) from s = v 0 to v k . If G is initialised as we defined, and then a sequence of relaxation steps occurs that includes, in order, relaxations of the edges ( v 0 , v 1 ) , ( v 1 , v 2 ) , . . . ( v k − 1 , v k ), then d [ v k ] = δ ( s, v k ). This holds no matter which other edge relaxations occur. SSSP 10
Proof of Lemma 4 • We show by induction that after the i th edge of path p is relaxed, we have d [ v i ] = δ ( s, v i ). • For the basis, i = 0 we have from the initialisation d [ v 0 ] = d [ s ] = 0 = δ ( s, s ). • By the upper bound property , the value of d [ s ] is never changes after initialisation. • For the inductive step, we assume that d [ v i − 1 ] = δ ( s, v i − 1 ), and we examine the relation of edge ( v i − 1 , v i ). • By the convergence property , we have after the relation d [ v i ] = δ ( v, v i ). Again, this equality is maintained thereafter. SSSP 11
Proof of Lemma 1 • Consider a vertex v that is reachable from s . Let p = ( v 0 , v 1 , . . . v k ) (with v 0 = s and v k = v ) be a shortest acyclic path from s to v . • The path has at most | V | − 1 edges, giving k ≤ | V | − 1. • Each of the iterations of the for loop relaxes all edges of E . Among the edges relaxed in the i th iteration we have the edge ( v i − 1 , v i ). • By the relaxation property we have d [ v ] = d [ v k ] = δ ( s, v k ) = δ ( v, v ) SSSP 12
Predecessor-subpath property Lemma 5 Let G = ( V, E ) be a weighted, directed graph with weight function w : E − → R , and let s ∈ V be a source vertex. Assume that G does not contain a negative cycle reachable from s . Then, if we execute relaxation steps resulting in d [ v ] = δ ( s, v ) for all v ∈ V . Then the predecessor subgraph G π is a shortest-path tree rooted at s . SSSP 13
Proof of Lemma 5 We have to show that all three shortest-paths tree properties hold. • The vertices that are reachable from s are the ones with finite d [ v ]. A vertex v ∈ V − { s } has s finite value d [ v ] if and only if π [ v ] � = nil . Thus, the vertices in V π are those reachable from s . • It remains to show that the unique path in G π are shortest paths. Let p = ( s = v 0 , v 1 , . . . v k = v ) be a path in G π . • For i = 1 , 2 , . . . k we have both d [ v i ] = δ ( s, v i ) and d [ v i ] ≥ d [ v i − 1 ] + w ( v i − 1 , v i ). Hence, w ( v i − 1 , v i ) ≤ δ ( s, v i ) − δ ( s, v i − 1 ) . • Summing the weights along p yields w ( p ) = � k i =1 w ( v i − 1 , v i ) ≤ � k i =1 ( δ ( s, v i ) − δ ( s, v i − 1 ))) = δ ( s, v k ) − δ ( s, v 0 ) = δ ( s, v k ) • Thus, w ( p ) ≤ δ ( s, v k ) and we can conclude w ( p ) = δ ( s, v k ) SSSP 14
since δ ( s, v k ) is a lower bound. p is a shortest path. SSSP 15
Correctness of Bellman-Ford Lemma 6 Let G = ( V, E ) be a weighted, directed graph with weight function w : E − → R , and let s ∈ V be a source vertex. Consider any shortest path p = ( v 1 , v 2 , . . . , v k ) from s = v 0 to v k . 1. If G contains no negative cycles that are reachable from s , then the algorithm returns true and we have d [ v ] = δ ( s, v ) for all vertices v ∈ V and the Bellman-Ford algorithm computes a shortest path tree rooted at s . 2. If G does contains a negative weight cycle reachable from s , then the algorithm returns false . SSSP 16
Proof of Lemma 6 • Suppose the graph does not contain a negative cycle that is reachable for s . – If a vertex v is reachable from s , then Lemma 1 shows that d [ v ] = δ ( s, v ). – In v is not reachable from v , d [ v ] = δ ( s, v ) = ∞ . This follows from the upper-bound property since we always have ∞ = δ ( u, v ) ≤ d [ v ], Hence, we have d [ v ] = ∞ . – The predecessor-subgraph property implies that G π is a shortest-path tree. – It remains to show that the Bellman-Ford returns true . At termination we have for all edges ( u, v ) ∈ E d [ v ] = δ ( s, v ) ≤ δ ( s, u ) + w ( u, v ) = d [ u ] + w ( u, v ) SSSP 17
Recommend
More recommend