


下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、SQL版本的Dijkstra最短路徑算法受這篇文章結尾處題目的啟發,我嘗試寫了一個SQL版本的Dijkstr撮短路徑算法。算法描述如下:前提假設:支持Str或者支持ssrt、isrte、rcwrreiteattadistat,t,已/知最短距離的點ableknow及距離)istat,int未/知最短距離的點ableunkn及暫時的距離)istat,int求節點1到其他所有節點的距離初始,各表包含的數據meta_distances各個節點之間的距離kdesaxIaxIaxIreategiDijkstraauretdse_fca1ds_ocolareistaistareista計算rataasse
2、lecrotpa中每一個sdistanceiststmp若經過aistae_a與源點的距離stistarista數據結構:/各/個節點之間的距離Tablemetasrcidstidistanseledistiasastatasrastistancesistances_nodesst更新k的距離信息insertoverwritetableunknown_nodesselectf2.nodeI(Ff1.nodeisnull,f2.distance,I(Ff1.distancef2.distance,f2.distance,f1.distance)fromtmp_distance_aasf1righ
3、touterjoinunknown_nodesasf2onf1.dst=f2.node挑選出最小的lode,放入known_nodes中insertintotableknown_nodesselectlode,distalcefromulklowl_lodeswheredistalce=mil(distalce)挑選出最小的lode,最為下一個)ivot_nodeselectlodeiltopivot_lodefromulklowl_lodeswheredistalce=mil(distalce)/從unknown_nodes中刪除最小lodeinsertoverwriteintounknow
4、n_nodesselect*fromunkown_nodeswheredistance=min(distance)計算jnknown_nodes中剩余node的數量selectcount(*)intounknown_nodes_countfromunknown_nodesEndWhilendjava版本publicclassDijkstraSamplepublicstaticvoidcompute(intpivotNode)intunknownNodesCount=1;while(true)if(hive.get(selectcount(*)fromunknown_nodes)f2.dista
5、nce,+f2.distance,+f1.distance+)+)+from+tmp_distance_aasf1+rightouterjoin+unknown_nodesasf2+on+f1.dst=f2.node);挑選出最小的node,放入known_nodes中hive.execute(insertintotableknown_nodes+select+node,+distance+from+unknown_nodes+where+distance=min(distance);挑選出最小的node,最為下一個pivot_nodepivotNode=hive.get(selectnode+from+unknown_nodes+where+distance=min(distance);從unknown_node中刪除最小nodehive.execute(insertoverwriteintounknown_nodes+select*+fromunkown_nodes+wheredistance!=min(distance);也許有人會問:用SQL實現這個算法的意義是什么?它與用常規語言寫出來的程序相比,幾乎沒有任
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 10萬千瓦風電項目可行性研究報告(范文參考)
- 2025年同等學力申碩《工商管理》預測試卷二
- C語言編程實踐試題及答案2025年
- JAVA編程測試與評估2025年計算機二級考試試題及答案
- 軟件測試多樣化學習資源試題及答案
- 常見ACCESS函數應用試題及答案
- 深刻認知軟件測試過程中的溝通技巧及試題及答案
- 敏捷環境下的測試策略試題及答案
- C語言學習技巧轉變試題及答案2025年
- 核心問題解析2025年嵌入式開發試題及答案
- 直播電商基礎試題及答案
- 人工智能在醫療領域應用知識測試卷及答案
- 《實驗室認可培訓》課件
- 乳腺癌診治指南與規范(2025年版)解讀
- 腰痛中醫護理常規
- 隧道檢測流程方案
- 2024年消防設施操作員真題及參考答案
- 防性騷擾安全教育
- 廣東省五年中考(2020-2024)化學真題試卷含答案
- 低慢小無人機偵測反制系統要求標準
- 大氣污染治理的國內外比較研究
評論
0/150
提交評論