Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem

Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem

ID:40384302

大小:693.88 KB

页数:17页

时间:2019-08-01

Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem _第1页
Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem _第2页
Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem _第3页
Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem _第4页
Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem _第5页
资源描述:

《Ch9.3-4 Shortest-Path Algorithm, Network Flow Problem 》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、§3ShortestPathAlgorithmsGivenadigraphG=(V,E),andacostfunctionc(e)foreE(G).ThelengthofapathPfromsourcetodestinationis(alsocalledc(ei)weightedpathlength).eiP1.Single-SourceShortest-PathProblemGivenasinputaweightedgraph,G=(V,E),andadistinguishedvertex,s,findtheshortestweightedpathfromstoever

2、yothervertexinG.Negative-cost22cyclev1v2v1v2Note:Ifthereisno4131041–103negative-costcycle,2222v3v4v5v3v4v5theshortestpath84845656fromstosis11definedtobezero.v6v7v6v71/17§3ShortestPathAlgorithmsUnweightedShortestPathsSketchoftheidea1vv20:v31221:v1andv6Breadth-first0vvv33452:vandvsearch24

3、1v6v733:vandv57ImplementationTable[i].Dist::=distancefromstov/*initializedtobeexceptifors*/Table[i].Known::=1ifvischecked;or0ifnotiTable[i].Path::=fortrackingthepath/*initializedtobe0*/2/17§3ShortestPathAlgorithmsvoidUnweighted(TableT){intCurrDist;VertexV,W;for(CurrDist=0;CurrDist

4、ex;CurrDist++){for(eachvertexV)if(!T[V].Known&&T[V].Dist==CurrDist){T[V].Known=true;for(eachWadjacenttoV)IfVisunknownif(T[W].Dist==Infinity){yethasDist

5、end-forCurrDist*/}T=O(

6、V

7、2)Theworstcase:v9v8v7v6v5v4v3v2v13/17§3ShortestPathAlgorithmsImprovement12voidUnweighted(TableT)v1v2{/*TisinitializedwiththesourcevertexSgiven*/023QueueQ;v3v4v5VertexV,W;v6v7Q=CreateQueue(NumVertex);MakeEmpty(Q);13Enqueue(S,Q);/*Enqueuethesourcevertex*/while(!IsEmp

8、ty(Q)){V=Dequeue(Q);DistPathT[V].Known=true;/*notreallynecessary*/v11v03v7for(eachWadjacenttoV)v22v01v5if(T[W].Dist==Infinity){v300T[W].Dist=T[V].Dist+1;v4v42v01T[W].Path=V;vEnqueue(W,Q);v53v022}/*end-ifDist==Infinity*/v61v03v6}/*end-while*/v73v04v31DisposeQueue(Q);/*freememory*/}T=O(

9、

10、V

11、+

12、E

13、)4/17§3ShortestPathAlgorithmsDijkstra’sAlgorithm(forweightedshortestpaths)LetS={sandv’swhoseshortestpathshavebeenfound}iForanyuS,definedistance[u]=minimallengthofpath{s(viS)u}.Ifthepathsaregeneratedinnon-decreasingorder,thentheshortestp

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。