


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、4 Shortest Paths ParisBrusselsBernMunichPragueVienna34618356619428550440727194311461542902Edsger Wybe Dijkstra (19302002)tsxr wib dkstraDijkstras algorithm Paris(巴黎)Brussels(比利時布魯塞爾)Bern(瑞士泊爾尼)Munich(慕尼黑)Prague(捷克布拉格)Vienna(維也納)346183566194285504407271001833461833460679749679749183183617346346346617
2、617904904617749749904904904Shortest Paths ProblemGiven a digraph G = ( V, E ), and a weighting function w( e ) 0 for e E( G ). The length of a path P from source to destination is 1. Single Source All DestinationsGiven a source v0. Determine a shortest path to each v V(G) v0 .Note: A path with minim
3、al number of vertices is NOT necessarily the shortest.v0v1v3v4v2v52010501515201035303453) v0 v3 v4 v12) v0 v3 v44) v0 v21) v0 v3PathLength10254545non-decreasing4 Shortest PathsLet S = v0 and vis whose shortest paths have been found For any u S, define distance u = minimal length of path v0 ( vi S )
4、u . If the paths are generated in non-decreasing order, then the shortest path must go through ONLY vi S ; u is chosen so that distance u = min wS | distance w (If u is not unique, then we may select any of them) ; /* Greedy Method */ if distance u1 distance u2 and we add u1 into S, then distance u2
5、 may change. If so, a shorter path from v0 to u2 must go through u1 and distance u2 = distance u1 + length().Implementation vi = 0, 1, ., n1 Note: LARGE_NO must be greater than maxw(ei), and maxdistancei +LARGE_NO wont overflow.4 Shortest Pathsvoid shortestpath ( int v, int cost MAX_VERTICES , int d
6、istance , int n, short int found ) int i, u, w ; for ( i = 0; i n; i+ ) /* initialization */ found i = FALSE ; distance i = cost v i ; /* end for-loop */ found v = TRUE ; distance v = 0 ; for ( i = 0; i n2; i+ ) u = choose ( distance, n, found ) ; /* O( n ) */ /* find the min distance not yet checke
7、d. */ found u = TRUE ; for ( w = 0; w n; w+ ) if ( !found w ) if ( distance u + cost u w distance w ) /* if adding u into S makes distancew shorter */ distance w = distance u + cost u w ; /* end for-loop */Tp = O( n2 )4 Shortest Pathsint choose(int distance, int n, short int found) int i, min, minpo
8、s; min = INT_MAX; minpos = -1; for(i=0; in; i+) if(distancei min & FALSE = foundi) min = distancei;minpos = i; return minpos;5 Activity Networks1. Activity On Vertex ( AOV ) NetworksExample Courses needed for a computer science degree at a hypothetical universityHow shall we convert this list into a
9、 graph?5 Activity Networks AOV Network := digraph G in which V( G ) represents activities ( e.g. the courses ) and E( G ) represents precedence relations(先序關(guān)系) ( e.g. means that C1 is a prerequisite(先修) course of C3 ).C1C3 i is a predecessor of j := there is a path from i to j i is an immediate pred
10、ecessor of j := E( G ) Then j is called a successor ( immediate successor ) of i Partial order(偏序) := a precedence relation which is both transitive(傳遞的) ( i k, k j i j ) and irreflexive(非自反的) ( i i is impossible ).Note: If the precedence relation is reflexive, then there must be an i such that i is
11、 a predecessor of i. That is, i must be done before i is started. Therefore if a project is feasible, it must be irreflexive.Feasible AOV network must be a dag (directed acyclic graph).5 Activity Networks【Definition】A topological order is a linear ordering of the vertices of a graph such that, for a
12、ny two vertices, i, j, if i is a predecessor of j in the network then i precedes j in the linear ordering.Note: The topological orders may not be unique for a network. For example, there are several ways (topological orders) to meet the degree requirements in computer science.GoalTest an AOV for feasibility, and generate a topological order if possible.Algorithmfor ( i = 0; i n; i+ ) if ever
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 環(huán)保設(shè)備安裝與維護服務(wù)合同
- 快遞合作協(xié)議合同
- 教育在線培訓(xùn)服務(wù)協(xié)議
- 建筑項目設(shè)計及施工合作協(xié)議
- 大灣區(qū)新興產(chǎn)業(yè)發(fā)展項目合作框架協(xié)議
- 環(huán)??萍柬椖垦邪l(fā)與推廣合同
- 總包單位簽訂分包合同
- 買賣手房反擔保合同
- 承包合同養(yǎng)殖合同
- 私人拖拉機買賣合同書
- 第五部分茶藝館的經(jīng)營與管理
- 《習(xí)作:那一刻-我長大了》課件ppt
- 小學(xué)道德與法治課堂生活化教學(xué)的策略講座稿
- 大學(xué)生返家鄉(xiāng)志愿服務(wù)證明
- (新版)網(wǎng)絡(luò)攻防知識考試題庫(含答案)
- 建筑工程資料檔案盒側(cè)面標簽
- 工程設(shè)計變更工程量計算表
- 動力工程及工程熱物理專業(yè)英語課件
- 幼兒系列故事繪本課件達芬奇想飛-
- 出納收入支出日記賬Excel模板
- 給水排水用格柵除污機通用技術(shù)條件
評論
0/150
提交評論