shortest paths problems cs420 lecture twelve
play

Shortest Paths Problems CS420 lecture twelve Given a - PDF document

7/20/10 Shortest Paths Problems CS420 lecture twelve Given a weighted directed graph G=(V,E) find the shortest path Shortest Paths


  1. 7/20/10 ¡ Shortest ¡Paths ¡Problems ¡ CS420 ¡lecture ¡twelve ¡ • Given ¡a ¡ weighted ¡directed ¡ graph ¡G=(V,E) ¡ ¡ ¡ ¡ ¡ ¡find ¡the ¡shortest ¡path ¡ ¡ Shortest ¡Paths ¡ – path ¡length ¡is ¡the ¡sum ¡of ¡its ¡edge ¡weights. ¡ ¡ wim ¡bohm ¡cs ¡csu ¡ • The ¡shortest ¡path ¡(SP) ¡from ¡u ¡to ¡v ¡is ¡ ∞ ¡if ¡there ¡ is ¡no ¡path ¡from ¡u ¡to ¡v. ¡ ¡ VariaIons ¡ VariaIons ¡ ¡1) ¡ SSSP ¡(Single ¡source ¡SP): ¡find ¡the ¡SP ¡from ¡ 3) ¡ SDSP ¡(single ¡desInaIon ¡SP) ¡can ¡use ¡1) ¡by ¡ some ¡node ¡s ¡to ¡all ¡nodes ¡in ¡the ¡graph. ¡ ¡ reversing ¡its ¡edges. ¡ ¡2) ¡ SPSP ¡(single ¡pair ¡SP): ¡find ¡the ¡SP ¡from ¡some ¡u ¡ to ¡some ¡v. ¡ ¡ 4) ¡ APSP ¡(all ¡pair ¡SPs) ¡could ¡be ¡solved ¡by ¡|V| ¡ We ¡can ¡use ¡1) ¡to ¡solve ¡2), ¡also ¡there ¡is ¡no ¡ ¡ applicaIons ¡of ¡1), ¡but ¡can ¡be ¡solved ¡faster. ¡ asymptoIcally ¡faster ¡algorithm ¡for ¡2) ¡than ¡that ¡ ¡ for ¡1). ¡ We ¡will ¡thus ¡concentrate ¡on ¡ SSSP ¡and ¡ APSP . ¡ ¡ 1 ¡

  2. 7/20/10 ¡ OpImal ¡Substructure ¡ NegaIve ¡weight ¡edges ¡and ¡cycles ¡ • Op1mal ¡Substructure ¡ • NegaIve ¡weight ¡cycles ¡create ¡an ¡ill ¡defined ¡ problem. ¡ Why? ¡ ¡ ¡ ¡ ¡ ¡ ¡the ¡property ¡that ¡the ¡SP ¡from ¡ u ¡to ¡v ¡via ¡w ¡ ¡ ¡ ¡ • If ¡some ¡weights ¡in ¡the ¡graph ¡are ¡negaIve ¡but ¡ ¡ ¡ ¡ ¡ ¡ ¡ consists ¡of ¡a ¡SP ¡from ¡u ¡to ¡w, ¡and ¡a ¡SP ¡from ¡w ¡ ¡ no ¡cycle ¡in ¡the ¡graph ¡has ¡a ¡negaIve ¡length, ¡ ¡ ¡ ¡ ¡ ¡ ¡to ¡v ¡ the ¡SP ¡problem ¡stays ¡well ¡defined. ¡ • Some ¡algorithms ¡(Dijkstra) ¡assume ¡all ¡weights ¡ ¡ ¡ ¡ ¡ ¡or ¡that ¡a ¡ sub ¡path ¡ from ¡p ¡to ¡q ¡ is ¡a ¡SP ¡ from ¡p ¡ ¡ to ¡be ¡posiIve, ¡some ¡(Bellman ¡Ford) ¡allow ¡ ¡ ¡ ¡ ¡ ¡to ¡q. ¡ negaIve ¡weights ¡but ¡not ¡negaIve ¡length ¡ cycles. ¡ Zero ¡length ¡cycles ¡ SSSP ¡and ¡Shortest ¡path ¡trees ¡ • ¡We ¡have ¡already ¡ruled ¡out ¡negaIve ¡length ¡ • For ¡each ¡vertex ¡v ¡on ¡the ¡shortest ¡path ¡(or ¡the ¡ cycles, ¡a ¡shortest ¡path ¡cannot ¡contain ¡a ¡ shortest ¡path ¡in ¡construcIon) ¡we ¡maintain ¡its ¡ posiIve ¡length ¡cycle, ¡what ¡about ¡ zero ¡length ¡ predecessor ¡ π (v) , ¡a ¡node ¡or ¡nil. ¡ cycles? ¡ ¡ • The ¡predecessor ¡sub ¡graph ¡G π ¡= ¡(V π , ¡E π ) ¡has ¡ • We ¡can ¡remove ¡zero ¡length ¡cycles ¡and ¡ the ¡verIces ¡v ¡and ¡edges ¡ π (v) ¡ ≠ nil ¡plus ¡the ¡ produce ¡a ¡path ¡with ¡the ¡same ¡length. ¡Hence ¡ source ¡s . ¡ ¡ we ¡can ¡assume ¡ ¡that ¡shortest ¡paths ¡have ¡no ¡ • Shortest ¡path ¡algorithms ¡make ¡G π ¡a ¡ shortest ¡ cycles ¡and ¡thus ¡have ¡ at ¡most ¡|V|-­‑1 ¡edges . ¡ path ¡tree ¡ with ¡ root ¡s ¡ with ¡shortest ¡paths ¡to ¡all ¡ verIces ¡ ¡ reachable ¡from ¡s. ¡ ¡ 2 ¡

  3. 7/20/10 ¡ d(v) ¡ ∞ ¡ • For ¡each ¡vertex ¡v ¡we ¡maintain ¡ d(v ), ¡the ¡ • ArithmeIc ¡with ¡ ∞ : ¡ shortest-­‑path ¡esImate: ¡ an ¡upper ¡bound ¡on ¡ the ¡shortest ¡path ¡length ¡to ¡v . ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡a ¡ ≠ ¡-­‑ ∞ , ¡we ¡have ¡a+ ∞ ¡= ¡ ∞ +a ¡= ¡ ∞ ¡ • We ¡iniIalize ¡d-­‑s ¡and ¡ π -­‑s ¡as ¡follows: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Init-­‑SingleSource ¡(G,s){ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡a ¡ ≠ ¡ ∞ , ¡a+(-­‑ ∞ )=(-­‑ ∞ )+a=-­‑ ∞ . ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for ¡each ¡vertex ¡v ¡{d[v]= ∞ ; ¡ π [v]=nil} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡d[s]=0; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ Relax ¡ δ (s,v) ¡ • Shortest ¡paths ¡algorithms ¡use ¡the ¡operaIon ¡ • The ¡final ¡value ¡for ¡d[v] ¡is ¡denoted ¡as ¡ δ (s,v) , ¡ relax ¡edge ¡(u,v) : ¡tesIng ¡whether ¡we ¡can ¡ the ¡shortest ¡path ¡from ¡s ¡to ¡v. ¡ improve ¡a ¡path ¡from ¡s ¡to ¡v ¡by ¡using ¡edge ¡(u,v) ¡ • Assuming ¡the ¡algorithm ¡starts ¡with ¡ ¡ and, ¡if ¡so, ¡updaIng ¡d[v] ¡and ¡ π [v]: ¡ ¡ ¡ ¡ Init-­‑SingleSource ¡and ¡only ¡does ¡updates ¡on ¡d ¡ ¡ ¡ ¡ ¡ ¡Relax(u,v,w) ¡{ ¡ and ¡ π ¡using ¡Relax , ¡the ¡following ¡properIes ¡of ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡(d[v] ¡> ¡(r ¡= ¡d[u]+w(u,v))) ¡ ¡ ¡ shortest ¡paths ¡and ¡relax ¡can ¡be ¡proved ¡ (Cormen ¡et. ¡al., ¡ch. ¡24.5). ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{d[v] ¡= ¡r; ¡ ¡ π [v]= ¡u} ¡ ¡ ¡ ¡ ¡ ¡} ¡ 3 ¡

  4. 7/20/10 ¡ ProperIes ¡ More ¡ProperIes ¡ • Triangle ¡Inequality: ¡ • No-­‑path ¡property: ¡ ¡ ¡ ¡ ¡ ¡ ¡For ¡any ¡edge ¡(u,v): ¡ δ (s,v) ¡<= ¡ δ (s,u) ¡+ ¡w(u,v) ¡ ¡ ¡ ¡ ¡If ¡there ¡is ¡no ¡path ¡from ¡s ¡to ¡v, ¡d[v]= ¡ δ (s,v)= ∞ ¡ ¡ ¡ ¡ ¡ ¡ op1mal ¡sub ¡structure ¡ ¡ ¡ ¡ ¡ relax ¡never ¡changed ¡d ¡ • Upper-­‑bound ¡Property: ¡ • ¡ Convergence ¡property: ¡ ¡ ¡ ¡ ¡d[v] ¡>= ¡ δ (s,v) ¡and ¡once ¡d[v] ¡achieves ¡ δ (s,v), ¡it ¡ ¡ ¡ ¡ ¡If ¡s ¡ ⇒ ¡u ¡ → ¡v ¡is ¡a ¡shortest ¡path ¡and ¡d[u]= ¡ δ (s,u) ¡ does ¡not ¡change ¡anymore. ¡ ¡ before ¡relaxing ¡edge ¡(u,v), ¡then ¡d[v] ¡= ¡ δ (s,v) ¡ agerward. ¡ ¡ ¡ ¡ ¡ ¡ ¡nature ¡of ¡relax ¡ ¡ ¡ ¡ op1mal ¡sub ¡structure ¡ and ¡more ¡ Bellman-­‑Ford ¡SSSP ¡ • Path-­‑relaxa1on ¡property: ¡ ¡ ¡ ¡ ¡If ¡p ¡= ¡<v 0 ,v 1 ,...,v k > ¡is ¡a ¡shortest ¡path ¡from ¡s=v 0 ¡ • Allows ¡negaIve ¡edge ¡weights ¡ to ¡v k, ¡ and ¡the ¡edges ¡are ¡relaxed ¡in ¡order ¡(v 0 ,v 1 ), ¡ • Checks ¡for ¡negaIve ¡length ¡cycles ¡ (v 1 ,v 2 ) ¡etc., ¡then ¡d[v]= ¡ δ (s,v). ¡ • returns ¡false ¡if ¡there ¡is ¡a ¡negaIve ¡length ¡cycle ¡ ¡ ¡ ¡ ¡ ¡induc1ve ¡argument ¡ ¡ • otherwise, ¡BF ¡returns ¡true ¡and ¡and ¡the ¡ • Predecessor-­‑subgraph ¡property: ¡ shortest ¡paths ¡in ¡d ¡and ¡the ¡shortest ¡path ¡tree ¡ ¡ ¡ ¡ ¡Once ¡d[v]= ¡ δ (s,v) ¡for ¡all ¡v ¡in ¡V, ¡the ¡predecessor ¡ in ¡ π . ¡ ¡ ¡ subgraph ¡is ¡the ¡shortest ¡path ¡tree ¡rooted ¡at ¡s. ¡ ¡ ¡ ¡ ¡ ¡nature ¡of ¡Relax ¡ 4 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend