1、 Some of the instance of the problems have negative weight edges Negative cycles: the negative infinitive length清华大学 63 10 5 11 清华大学 7Cycles Can a shortest path contains cycles: Case 1. Positive Cycles: never occurs Case 2. Negative Cycles: - Case 3. zero Cycles: removable清华大学 9Representing shortest
2、 paths Using predecessor label can get the result. Let G =(V, E) be a graph : VV null Shortest-paths tree rooted at s is a directed subgraph G = (V, E) of G. V is the set of vertices reachable from s in G G forms a rooted tree with root s and For all v V , the unique simple path from s to v in Gis a
3、 shortest path from s to v in G清华大学 10Relaxation We using the technique of relaxation: Let dv be a shortest-path of estimate, it must be great than or equal to its real distance of v from s, the source. Initialize-Single-Source(G,s)1. For each vertex v VG1. dv = 2. v=null2. ds=0清华大学 14Some comments
4、on relaxation 松弛什么? Relax the constrain of triangle inequality清华大学 16Relax Relax(u,v,w)1. If dvdu+w(u,v)1. dvdu+w(u,v)2. vu清华大学 17Properties and relaxation1. Triangle inequality: for any (u,v)E we have(s,v)(s,u)+w(u,v)2. Upper bound property: we always have dv(s,v) for all vertices v V, and once dv
5、achieves the value (s,v), it never changes3. No path property: if there is no path from s to v, we always have dv=(s,v) =清华大学 18Properties4. Convergence property: if p= is a shortest path in G for some u,v V, and if du= (s,u) at any time prior to relaxing edge (u,v), then dv=(s,v) at all time afterw
6、ard5. Path relaxation property:v0,v1, vk is a shortest path from v0 =s to vk, and the edges in p are relaxed in the order (v0,v1), (v1,v2),(vk-1,vk), then dvk= (s,vk). This property holds regardless of any other relaxation steps that occurs.清华大学 19Properties:6. Predecessor-subgraph property: Once dv
7、=(s,v) for all v in V, the predecessor subgraph is a shortest-paths tree rooted at s.清华大学 20Bellman-Ford algorithm Bellman-Ford(G,w,s)1. Initialize-Single-Source(G,s)2. For i1 to |VG|-11. For each edge (u,v)EG1. Relax(u,v,w)3. For each edge (u,v)EGdu+w(u,v) return false4. Return true清华大学 21The corre
8、ctness of Bellman-Ford algorithm1. 如果没有由s可达的负圈:1. 则再结束时,验证通过,且距离正确。2. 如果有由s可达的负圈:1. 设此圈为,若所有三角不等式成立,则与此负圈矛盾。【】清华大学 29Si dingle-source shortest paths in a rected acyclic graph Dag-shortest-paths(G,w,s)1. Topological sort the vertices of G2. Initialize-Single-Source(G,w,s)3. For each vertex u, taken i
9、n topological order1. For each v in Adju清华大学 30Dags Shortest-paths31Dijkstras Algorithm It solves the problem of nonnegative weighted graphs shortest-paths Its main trick is to maintain a set S of vertices whose final shortest-path weights from the source s have already been determined.清华大学 32 Dijks
10、tra(G,w,s)1. Initialize-SingleSource(G,s)2. S3. QVG4. While Q != 1. uQ.extractMin()2. S S U u3. For each vertex v in Adju清华大学 33Complex analysisThe Maintaining of Minimum Queue by calling:1.Insert2.Extract3.Decrease key4.Using aggregate analysis, we have O(V+E)lg V)5.By using Fibonacci heap, the run
11、ning time is O(V lgV + E), by reducing the amortized cost ofdecreasing key operations38Application of Shortest paths 图像缝合问题: Linear programming with difference constraints can be equivalently converted to a problem of shortest path of a graph.【可行解问题】清华大学 39The linear programming problem Ob j ect: ni
12、=1 cixi subject to xj-xi bk for i,j in 1,2,n Converting to a graph! 如何找到可行解! n vertices represent the n variables plus an artificial vertex v0, xj-xi bk means to add an edge (i,j) with weight bk Constraints convert to the Edges between the vertices and plus artificial edges (v0,v1), (v0,vn) X=(d(v0,
13、v1), d(v0,v2), , d(v0,vn),) is a feasiblesolution of the linear programming problem清华大学 40所有点之间的最短路径 动态规划方法: 最优解结构: 设l(k)ij为最多包含k条边的从顶点i到顶点j的最短路径的距离,如果没有这样的路径,则距离定义为,于是 l(0) 0 if ij, otherwiseij l(1) w(i,j), what is w? l(m)ijmin(l(m-1)ij, p(m)ij) p(m)ijmink=1,n(l(m-1)ik + w(k,j) ) l(m) min (l(m-1) +
14、 w(k,j) ) Why?ij k=1,n ik清华大学 41(k)ij每个顶点每条路径的前驱 (k)ij=?如何计算 与上面计算相关!清华大学 42问题的解 什么是(i,j), We claim: (i,j)=l(n-1)ij =l(n)ij =l(n+1) (n+2)ij =l ij 为什么?清华大学 43算法11. LW;2. For i 1,n1. LExtended-Shortest-Paths(L,W)清华大学 45Floyd-Warshall algorithm 设d(k)ij为最多包含k个中间点的顶点i到顶点j的最短路径的距离,如果没有这样的路径,则距离定义为,于是 d(0)
15、ijw(i,j), (0)ij = null if there is no edge (i,j), else it is i. d(m)ijmin(d(m-1)ij, d(m-1)im+d(m-1)mj) Why? 如何计算(k) ,从i 到j最多包含k个中间点的最短路径中j的ij父节点? 由(n) 计算最短路径。 复杂度:O(V3)清华大学 48Johnson算法 针对稀疏矩阵,Johnson提出一种更为有效的算法。 引理25.1 改变加权函数不改变最短路径: 设:h: ER 定义: w ( u , v ) = w ( u , v ) + h ( u ) - h ( v ) 设p是从v0到v
16、k的任意路径, 则p是从v0到vk的在权W下的最短路径的充要条件是: 从v0到vk的在权 w 的最短路径,G在权W下有负回路的充要条件是G在权 w 有负回路。清华大学 49W下Johnson(G)计算G1. VG=VG U s2. EG=EG U (s,v):v in VG, 且 w(s,v)=0如果Bellman-Ford(G,w,s) = flase1. Print 图有负回路,return null;For each (u,v) in EG1. w(u,v)= w(u,v)+(s,u)-(s,v)For each u in VG1. Dijkstra(G,w,u) 得到 (u,v) ,对所有v 属于VG2. 对所有 v 属于 VG1. duv = (u,v)- (s,u)+(s,v)5. Return D = (duv)nn52复杂性分析1. 计算G: O(V+E)2. Bellman-Ford算法:O(VE)3. O(E)4. O(V * Dijkstra算法复杂性)O(V * (V lg V+ E) = O(V2 lg V +VE)清华大学 53总结 单源最短路径问题 方法:贪婪:Dijkstra;Bellman Ford 关键点:松弛 应用:最优化问题、图像处理、 多源最短路径问题 动态规划问题:不同子空间设立 群论及其应用 问题转换54
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1