![1910072盧富毓插點(diǎn)問(wèn)題_第1頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e1.gif)
![1910072盧富毓插點(diǎn)問(wèn)題_第2頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e2.gif)
![1910072盧富毓插點(diǎn)問(wèn)題_第3頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e3.gif)
![1910072盧富毓插點(diǎn)問(wèn)題_第4頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e4.gif)
![1910072盧富毓插點(diǎn)問(wèn)題_第5頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/6/5605e7e7-3191-4827-a12a-41376182d16e/5605e7e7-3191-4827-a12a-41376182d16e5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、云南大學(xué)數(shù)學(xué)與統(tǒng)計(jì)學(xué)院 實(shí) 驗(yàn) 報(bào) 告課程名稱:算法圖論實(shí)驗(yàn)學(xué)期:20132014學(xué)年上學(xué)期成績(jī):指導(dǎo)教師:李建平姓名:盧富毓學(xué)號(hào):20101910072實(shí)驗(yàn)名稱:插值點(diǎn)問(wèn)題實(shí)驗(yàn)要求:必做實(shí)驗(yàn)學(xué)時(shí):2學(xué)時(shí)實(shí)驗(yàn)編號(hào):02實(shí)驗(yàn)日期:2013-10-10完成日期:2013-10-21學(xué)院:數(shù)學(xué)與統(tǒng)計(jì)學(xué)院專業(yè) :信息與計(jì)算科學(xué)年級(jí):2010級(jí) 一、實(shí)驗(yàn)?zāi)康睦胐ijskra算法實(shí)現(xiàn)路的插點(diǎn)問(wèn)題,掌握如何尋找最短路集合的方法二、實(shí)驗(yàn)環(huán)境vs2010(c+)三、實(shí)驗(yàn)內(nèi)容最短路的插點(diǎn)問(wèn)題:給定一個(gè)連通賦權(quán)圖g=(v,e;w.c;s.t)以及正整數(shù)d,這里w,c:e-r+s和t 是兩個(gè)固定的頂點(diǎn),找到s 到
2、t 的最短路集合構(gòu)造一個(gè)新的輔助圖,然后修改權(quán)值,再次調(diào)用dijskra算法尋求最短路。4、 實(shí)驗(yàn)過(guò)程a、插值算法具體描述如下:s和t 是兩個(gè)固定的頂點(diǎn),在圖g中尋找一條從s到t的路ps,t,使得路ps,t的權(quán)重w(ps,t)不超過(guò)常數(shù)b,并向路ps,t的一些特殊邊上插入一些頂點(diǎn),不妨設(shè)得到的新路為p*s,t,使得新路中任意邊的權(quán)重都不超過(guò)常數(shù)的d,目標(biāo)是在滿足上述條件情況下,求出插入頂點(diǎn)后所產(chǎn)生的費(fèi)用達(dá)到最小.即實(shí)現(xiàn),這里insert(e)表示加入到邊e中新點(diǎn)的個(gè)數(shù)。dijskra算法即標(biāo)號(hào)法,在上學(xué)期學(xué)過(guò),這里就不作贅述。b、算法運(yùn)行結(jié)果如下:/圖的輸入/圖的創(chuàng)建以及插值點(diǎn)的限制/最后插值
3、點(diǎn)的結(jié)果五、實(shí)驗(yàn)總結(jié)通過(guò)編程,對(duì)尋找最短路徑的dijkstra算法也體會(huì)更深;復(fù)習(xí)了求最短路的算法,思考了反圈算法在其中的一些應(yīng)用。六、源代碼#include#include#include#includeusing namespace std;#define max_vex 100#define m 1000/settextc1是原來(lái)的顏色/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)長(zhǎng)度和dbool pmax_vexmax_vex;/最短路徑pstring vex,vex2;int v0,v1;class arcllpublic:double weight; /權(quán)重;class graphics /創(chuàng)建一個(gè)圖的類private:int ve
7、xnum; /頂點(diǎn)數(shù)int arcnum; /邊數(shù)string vexsmax_vex; /存儲(chǔ)定點(diǎn)名稱arcll arcsmax_vexmax_vex; /邊數(shù)double d;/邊的限制public:void creategraphics(graphics &g);/創(chuàng)建一個(gè)圖int locateindex(graphics g, string v); / 尋找下標(biāo)void dijkstra(graphics &g);void insertpoint(graphics &g);/找到相應(yīng)頂點(diǎn)的下標(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)建一個(gè)圖void graphics:creategraphics(graphics &g)int i,j,k;string vi,vj;double w; /權(quán)值settextc1;cout-創(chuàng)建有向圖的存儲(chǔ)-endl;coutg.vexnum;settextc1;/設(shè)置顏色coutg.arcnum;settextc1;cout請(qǐng)輸入頂點(diǎn)名:;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請(qǐng)輸入第k+1vivjw;settextc1;i = locateindex(g,vi);j = locateindex(g,vj);if(i = -1 | j = -1)cout輸入錯(cuò)誤!請(qǐng)檢查.endl;return;g.arcsij.weight = w;g.arcsji.weight = w;coutendl;cout各頂點(diǎn)的關(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輸入錯(cuò)誤!請(qǐng)檢查.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的最短路長(zhǎng)度:;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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 個(gè)人二手商鋪買賣合同協(xié)議書
- 個(gè)人間借款合同樣本:版
- 個(gè)人股權(quán)抵押合同范例
- 三方合同:學(xué)生就業(yè)定向合作
- 專屬應(yīng)屆畢業(yè)生:個(gè)人租賃合同范本
- 中學(xué)教務(wù)主任聘任合同樣本
- 單項(xiàng)木工承包合同
- 中外采購(gòu)與供應(yīng)合同范本
- 專業(yè)水處理設(shè)備維護(hù)合同細(xì)則
- 三人合伙經(jīng)營(yíng)合同范本
- 中醫(yī)中風(fēng)病(腦梗死)診療方案
- GMP-基礎(chǔ)知識(shí)培訓(xùn)
- 人教版小學(xué)六年級(jí)數(shù)學(xué)下冊(cè)(全冊(cè))教案
- 人教版二年級(jí)語(yǔ)文上冊(cè)同音字歸類
- 高二數(shù)學(xué)下學(xué)期教學(xué)計(jì)劃
- 文學(xué)類作品閱讀練習(xí)-2023年中考語(yǔ)文考前專項(xiàng)練習(xí)(浙江紹興)(含解析)
- SB/T 10624-2011洗染業(yè)服務(wù)經(jīng)營(yíng)規(guī)范
- 第五章硅酸鹽分析
- 外科學(xué)總論-第十四章腫瘤
- 網(wǎng)絡(luò)反詐知識(shí)競(jìng)賽參考題庫(kù)100題(含答案)
- 運(yùn)動(dòng)技能學(xué)習(xí)與控制課件第四章感覺(jué)系統(tǒng)對(duì)運(yùn)動(dòng)控制的作用
評(píng)論
0/150
提交評(píng)論