版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、實驗名稱: 第十一章 最短路問題 一、實驗內(nèi)容與要求掌握Dijkstra算法和Floyd算法,并運用這兩種算法求一些最短路徑的問題。二、實驗軟件MATLAB7.0三、實驗內(nèi)容1、在一個城市交通系統(tǒng)中取出一段如圖所示,其入口為頂點v1,出口為頂點v8,每條弧段旁的數(shù)字表示通過該路段所需時間,每次轉(zhuǎn)彎需要附加時間為3,求v1到 v8的最短時間路徑。V1 1 V2 3 V3 1 V5 6 V62 23 V4 2 V7 4 V8程序:function y=bijiaodaxiao(f1,f2,f3,f4)v12=1;v23=3;v24=2;v35=1;v47=2;v57=2;v56=6;v68=3;v
2、78=4;turn=3;f1=v12+v23+v35+v56+turn+v68;f2=v12+v23+v35+turn+v57+turn+v78;f3=v12+turn+v24+turn+v47+v78;f4=v12+turn+v24+v47+turn+v57+turn+v56+turn+v68;min=f1;if f2<min min=f2;endif f3<min min=f3;endif f4<min min=f4;endminf1f2f3f4實驗結(jié)果:v1到v8的最短時間路徑為15,路徑為1-2-4-7-8.2、求如圖所示中每一結(jié)點到其他結(jié)點的最短路。 V1 10 V
3、3 V5 9 V636 4 5 3 4 V2 5 V4 10 V7 6 V8floy.m中的程序:functionD,R=floyd(a)n=size(a,1);D=afor i=1:n for j=1:n R(i,j)=j; endendRfor k=1:n for i=1:n for j=1:n if D(i,k)+D(k,j)<D(i,j) D(i,j)=D(i,k)+D(k,j); R(i,j)=R(i,k); end end end k D Rend程序:>> a=0 3 10 inf inf inf inf inf;3 0 inf 5 inf inf inf in
4、f;10 inf 0 6 inf inf inf inf;inf 5 6 0 4 inf 10 inf ;inf inf inf 4 0 9 5 inf ;inf inf inf inf 9 0 3 4;inf inf inf 10 5 3 0 6;inf inf inf inf inf 4 6 0;D,R=floyd(a)實驗結(jié)果:D = 0 3 10 Inf Inf Inf Inf Inf 3 0 Inf 5 Inf Inf Inf Inf 10 Inf 0 6 Inf Inf Inf Inf Inf 5 6 0 4 Inf 10 Inf Inf Inf Inf 4 0 9 5 Inf I
5、nf Inf Inf Inf 9 0 3 4 Inf Inf Inf 10 5 3 0 6 Inf Inf Inf Inf Inf 4 6 0R = 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8k = 1D = 0 3 10 Inf Inf Inf Inf Inf 3 0 13 5 Inf Inf Inf Inf 10 13 0 6 Inf Inf Inf Inf Inf 5 6 0 4
6、 Inf 10 Inf Inf Inf Inf 4 0 9 5 Inf Inf Inf Inf Inf 9 0 3 4 Inf Inf Inf 10 5 3 0 6 Inf Inf Inf Inf Inf 4 6 0R = 1 2 3 4 5 6 7 8 1 2 1 4 5 6 7 8 1 1 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8k = 2D = 0 3 10 8 Inf Inf Inf Inf 3 0 13 5 Inf Inf Inf Inf 10
7、 13 0 6 Inf Inf Inf Inf 8 5 6 0 4 Inf 10 Inf Inf Inf Inf 4 0 9 5 Inf Inf Inf Inf Inf 9 0 3 4 Inf Inf Inf 10 5 3 0 6 Inf Inf Inf Inf Inf 4 6 0R = 1 2 3 2 5 6 7 8 1 2 1 4 5 6 7 8 1 1 3 4 5 6 7 8 2 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8k = 3D = 0 3 10 8 Inf Inf In
8、f Inf 3 0 13 5 Inf Inf Inf Inf 10 13 0 6 Inf Inf Inf Inf 8 5 6 0 4 Inf 10 Inf Inf Inf Inf 4 0 9 5 Inf Inf Inf Inf Inf 9 0 3 4 Inf Inf Inf 10 5 3 0 6 Inf Inf Inf Inf Inf 4 6 0R = 1 2 3 2 5 6 7 8 1 2 1 4 5 6 7 8 1 1 3 4 5 6 7 8 2 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5
9、6 7 8k = 4D = 0 3 10 8 12 Inf 18 Inf 3 0 11 5 9 Inf 15 Inf 10 11 0 6 10 Inf 16 Inf 8 5 6 0 4 Inf 10 Inf 12 9 10 4 0 9 5 Inf Inf Inf Inf Inf 9 0 3 4 18 15 16 10 5 3 0 6 Inf Inf Inf Inf Inf 4 6 0R = 1 2 3 2 2 6 2 8 1 2 4 4 4 6 4 8 1 4 3 4 4 6 4 8 2 2 3 4 5 6 7 8 4 4 4 4 5 6 7 8 1 2 3 4 5 6 7 8 4 4 4 4
10、 5 6 7 8 1 2 3 4 5 6 7 8k = 5D = 0 3 10 8 12 21 17 Inf 3 0 11 5 9 18 14 Inf 10 11 0 6 10 19 15 Inf 8 5 6 0 4 13 9 Inf 12 9 10 4 0 9 5 Inf 21 18 19 13 9 0 3 4 17 14 15 9 5 3 0 6 Inf Inf Inf Inf Inf 4 6 0R = 1 2 3 2 2 2 2 8 1 2 4 4 4 4 4 8 1 4 3 4 4 4 4 8 2 2 3 4 5 5 5 8 4 4 4 4 5 6 7 8 5 5 5 5 5 6 7
11、8 5 5 5 5 5 6 7 8 1 2 3 4 5 6 7 8k = 6D = 0 3 10 8 12 21 17 25 3 0 11 5 9 18 14 22 10 11 0 6 10 19 15 23 8 5 6 0 4 13 9 17 12 9 10 4 0 9 5 13 21 18 19 13 9 0 3 4 17 14 15 9 5 3 0 6 25 22 23 17 13 4 6 0R = 1 2 3 2 2 2 2 2 1 2 4 4 4 4 4 4 1 4 3 4 4 4 4 4 2 2 3 4 5 5 5 5 4 4 4 4 5 6 7 6 5 5 5 5 5 6 7 8
12、 5 5 5 5 5 6 7 8 6 6 6 6 6 6 7 8k = 7D = 0 3 10 8 12 20 17 23 3 0 11 5 9 17 14 20 10 11 0 6 10 18 15 21 8 5 6 0 4 12 9 15 12 9 10 4 0 8 5 11 20 17 18 12 8 0 3 4 17 14 15 9 5 3 0 6 23 20 21 15 11 4 6 0R = 1 2 3 2 2 2 2 2 1 2 4 4 4 4 4 4 1 4 3 4 4 4 4 4 2 2 3 4 5 5 5 5 4 4 4 4 5 7 7 7 7 7 7 7 7 6 7 8
13、5 5 5 5 5 6 7 8 7 7 7 7 7 6 7 8k = 8D = 0 3 10 8 12 20 17 23 3 0 11 5 9 17 14 20 10 11 0 6 10 18 15 21 8 5 6 0 4 12 9 15 12 9 10 4 0 8 5 11 20 17 18 12 8 0 3 4 17 14 15 9 5 3 0 6 23 20 21 15 11 4 6 0R = 1 2 3 2 2 2 2 2 1 2 4 4 4 4 4 4 1 4 3 4 4 4 4 4 2 2 3 4 5 5 5 5 4 4 4 4 5 7 7 7 7 7 7 7 7 6 7 8 5 5 5 5 5 6 7 8 7 7 7 7 7 6 7 8D = 0 3 10 8 12 20 17 23 3 0 11 5 9 17 14 20 10 11 0 6 10 18 15 21 8 5 6 0 4 12 9 15 12 9
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 七一活動合同范本
- 焊接包工合同范本
- 提高倉庫應(yīng)對突發(fā)事件的能力計劃
- 促進(jìn)學(xué)生團(tuán)隊合作能力的培養(yǎng)計劃
- 《公司戰(zhàn)略與風(fēng)險管理》第3版 課件全套 呂文棟 第1-9章 戰(zhàn)略與戰(zhàn)略管理- 公司治理與戰(zhàn)略管理、風(fēng)險管理
- 城市房屋拆遷便民手冊
- 2018年下半年企業(yè)人力資源管理師(三級)《理論知識》試題(網(wǎng)友回憶版)
- SMP-06-006-00 批記錄管理規(guī)程
- 七年級歷史上冊 第四單元 第16課 三國鼎立教案 新人教版
- 六年級品德與社會下冊 第一單元 生命需要呵護(hù) 第1課《生命的奧秘》教案 粵教版
- 東湖街道房屋租賃合同范本
- 【高中物理】光的折射+課件+高二上學(xué)期物理人教版(2019)選擇性必修第一冊+
- 2023學(xué)年完整公開課版望大陸
- 六年級數(shù)學(xué)上冊第三單元例工程問題
- 奔馳汽車介紹PPT
- 普速鐵路道口大修作業(yè)指導(dǎo)書
- 心理投影生幻覺注重心理描寫和幻覺
- 城市規(guī)劃原理課件-經(jīng)濟(jì)與產(chǎn)業(yè)
- 單片機(jī)理論題庫(有答案)
- GB/T 18916.3-2002取水定額第3部分:石油煉制
- 冷鏈?zhǔn)称稧MP培訓(xùn)試題及答案
評論
0/150
提交評論