![1910072盧富毓插點問題_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e1.gif)
![1910072盧富毓插點問題_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e2.gif)
![1910072盧富毓插點問題_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e3.gif)
![1910072盧富毓插點問題_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e4.gif)
![1910072盧富毓插點問題_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、云南大學(xué)數(shù)學(xué)與統(tǒng)計學(xué)院 實 驗 報 告課程名稱:算法圖論實驗學(xué)期:20132014學(xué)年上學(xué)期成績:指導(dǎo)教師:李建平姓名:盧富毓學(xué)號:20101910072實驗名稱:插值點問題實驗要求:必做實驗學(xué)時:2學(xué)時實驗編號:02實驗日期:2013-10-10完成日期:2013-10-21學(xué)院:數(shù)學(xué)與統(tǒng)計學(xué)院專業(yè) :信息與計算科學(xué)年級:2010級 一、實驗?zāi)康睦胐ijskra算法實現(xiàn)路的插點問題,掌握如何尋找最短路集合的方法二、實驗環(huán)境vs2010(c+)三、實驗內(nèi)容最短路的插點問題:給定一個連通賦權(quán)圖g=(v,e;w.c;s.t)以及正整數(shù)d,這里w,c:e-r+s和t 是兩個固定的頂點,找到s 到
2、t 的最短路集合構(gòu)造一個新的輔助圖,然后修改權(quán)值,再次調(diào)用dijskra算法尋求最短路。4、 實驗過程a、插值算法具體描述如下:s和t 是兩個固定的頂點,在圖g中尋找一條從s到t的路ps,t,使得路ps,t的權(quán)重w(ps,t)不超過常數(shù)b,并向路ps,t的一些特殊邊上插入一些頂點,不妨設(shè)得到的新路為p*s,t,使得新路中任意邊的權(quán)重都不超過常數(shù)的d,目標(biāo)是在滿足上述條件情況下,求出插入頂點后所產(chǎn)生的費用達到最小.即實現(xiàn),這里insert(e)表示加入到邊e中新點的個數(shù)。dijskra算法即標(biāo)號法,在上學(xué)期學(xué)過,這里就不作贅述。b、算法運行結(jié)果如下:/圖的輸入/圖的創(chuàng)建以及插值點的限制/最后插值
3、點的結(jié)果五、實驗總結(jié)通過編程,對尋找最短路徑的dijkstra算法也體會更深;復(fù)習(xí)了求最短路的算法,思考了反圈算法在其中的一些應(yīng)用。六、源代碼#include#include#include#includeusing namespace std;#define max_vex 100#define m 1000/settextc1是原來的顏色/settextc2 是設(shè)置的輸出輸入顏色#define settextc1 setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity | foreground
4、_red | foreground_green |foreground_blue)#define settextc2 setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity | foreground_green)#define settextc3 setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity | foreground_green | foreground_blue)#define sette
5、xtc4 setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity | foreground_red)#define settextc5 setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity | foreground_red | foreground_blue)#define settextc6 setconsoletextattribute(getstdhandle(std_output_handl
6、e),foreground_red | foreground_green |foreground_blue)#define settextc7 setconsoletextattribute(getstdhandle(std_output_handle),foreground_green)double dmax_vex;/最短路徑p帶權(quán)長度和dbool pmax_vexmax_vex;/最短路徑pstring vex,vex2;int v0,v1;class arcllpublic:double weight; /權(quán)重;class graphics /創(chuàng)建一個圖的類private:int ve
7、xnum; /頂點數(shù)int arcnum; /邊數(shù)string vexsmax_vex; /存儲定點名稱arcll arcsmax_vexmax_vex; /邊數(shù)double d;/邊的限制public:void creategraphics(graphics &g);/創(chuàng)建一個圖int locateindex(graphics g, string v); / 尋找下標(biāo)void dijkstra(graphics &g);void insertpoint(graphics &g);/找到相應(yīng)頂點的下標(biāo)int graphics:locateindex(graphics g, string v)i
8、nt i=0;for(i=0; ig.vexnum; i+)if(g.pare(v) = 0)return i;return -1;/創(chuàng)建一個圖void graphics:creategraphics(graphics &g)int i,j,k;string vi,vj;double w; /權(quán)值settextc1;cout-創(chuàng)建有向圖的存儲-endl;coutg.vexnum;settextc1;/設(shè)置顏色coutg.arcnum;settextc1;cout請輸入頂點名:;settextc4;for(i=0; ig.vexsi;settextc1;for(i=0; ig.
9、vexnum; i+) /初始化邊f(xié)or(j=0; jg.vexnum; j+)g.arcsij.weight = m;for(k=0; kg.arcnum; k+)cout請輸入第k+1vivjw;settextc1;i = locateindex(g,vi);j = locateindex(g,vj);if(i = -1 | j = -1)cout輸入錯誤!請檢查.endl;return;g.arcsij.weight = w;g.arcsji.weight = w;coutendl;cout各頂點的關(guān)系:endl;settextc2;for(i=0; ig.vexnum; i+) if(
10、i=0)coutttg.vexsi ;else couttg.vexsi ;coutendl;settextc3;for(i=0; ig.vexnum; i+) /初始化邊settextc2;couttg.vexsi ;settextc3;for(j=0; jg.vexnum; j+)if(g.arcsij.weight = m)settextc6;couttm ;settextc3; else couttg.arcsij.weight ;coutendl;settextc1;coutendl圖創(chuàng)建完畢!endl;coutvex;coutendlvex2;coutendlg.d;/*-dijk
11、stra算法-*/void graphics:dijkstra(graphics &g)/bool pmax_vexmax_vex;/最短路徑pbool finalmax_vex;/控制變量int i,j,v,w;double min;cout-v0到v1的最短路徑-endl;v0 = locateindex(g,vex);v1 = locateindex(g,vex2);if(v0 = -1 | v1= -1)cout輸入錯誤!請檢查.endl;return;for(v = 0; v g.vexnum; v+ ) /初始化finalv = false;dv = g.arcsv0v.weigh
12、t;for(w = 0; w g.vexnum; w+)pvw = false;if(dv m)pvv0 = true;pvv = true;dv0 = 0;finalv0 = true;for(i = 1; i g.vexnum; +i)min = m;for(w = 0; w g.vexnum; +w)if(!finalw)if(dwmin)v = w;min = dw; finalv = true;for(w = 0; w g.vexnum; +w)if(!finalw & (min + g.arcsvw.weight dw)dw = min + g.arcsvw.weight;for(
13、j = 0; jg.vexnum; +j)pwj = pvj;pww = true;if(dv1=m)cout不連通!最短路不存在!endl;elsecout從g.vexsv0到g.vexsv1的最短路長度:;coutdv1endl;/*-路的插值算法-*/void graphics:insertpoint(graphics &g)int i,j;for(i=0;ig.vexnum;i+)for(j=0;jg.vexnum;j+)if(i=j)continue;elseif(g.arcsij.weight+di=dj)g.arcsij.weight = ceil(g.arcsij.weight
14、/g.d)-1;elseg.arcsij.weight=m;coutendl;settextc2;for(i=0; ig.vexnum; i+) if(i=0)coutttg.vexsi ; else couttg.vexsi ;coutendl;for(i=0; ig.vexnum; i+)settextc2;couttg.vexsi ;settextc3;for(j=0; jg.vexnum; j+)if(g.arcsij.weight = m)if(g.arcsji.weight!= m)g.arcsij.weight = g.arcsji.weight;couttg.arcsij.weight ; else settextc6;couttm ;settextc3; else couttg.arcsij.weight ;coutendl;settextc6;g.dijkstra(g);/構(gòu)造新的權(quán)值后,再尋找最短路cout最短路:;for(j=0;
溫馨提示
- 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)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 26《好的故事》說課稿-2024-2025學(xué)年語文六年級上冊統(tǒng)編版
- 1場景歌說課稿-2024-2025學(xué)年統(tǒng)編版語文二年級上冊
- 2024年秋一年級道德與法治下冊 第二單元 我和大自然 5 風(fēng)兒輕輕吹說課稿 新人教版
- 18古詩三首浪淘沙(其一)說課稿-2024-2025學(xué)年六年級上冊語文統(tǒng)編版
- 8 設(shè)計制作小車(二) 說課稿-2024-2025學(xué)年科學(xué)四年級上冊教科版
- 23《月光曲》說課稿-2024-2025學(xué)年語文六年級上冊統(tǒng)編版
- 1 24時計時法(說課稿)-2024-2025學(xué)年三年級上冊數(shù)學(xué)人教版001
- 2023九年級道德與法治上冊 第三單元 文明與家園 第五課 守望精神家園第2框 凝聚價值追求說課稿 新人教版
- 2025北京市飼料采購合同新
- 2025建造船舶所要用到的合同
- 中醫(yī)中風(fēng)病(腦梗死)診療方案
- GMP-基礎(chǔ)知識培訓(xùn)
- 人教版小學(xué)六年級數(shù)學(xué)下冊(全冊)教案
- 人教版二年級語文上冊同音字歸類
- 高二數(shù)學(xué)下學(xué)期教學(xué)計劃
- 文學(xué)類作品閱讀練習(xí)-2023年中考語文考前專項練習(xí)(浙江紹興)(含解析)
- SB/T 10624-2011洗染業(yè)服務(wù)經(jīng)營規(guī)范
- 第五章硅酸鹽分析
- 外科學(xué)總論-第十四章腫瘤
- 網(wǎng)絡(luò)反詐知識競賽參考題庫100題(含答案)
- 運動技能學(xué)習(xí)與控制課件第四章感覺系統(tǒng)對運動控制的作用
評論
0/150
提交評論