版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验名称: 第十一章 最短路问题 一、实验内容与要求掌握Dijkstra算法和Floyd算法,并运用这两种算法求一些最短路径的问题。二、实验软件MATLAB7.0三、实验内容1、在一个城市交通系统中取出一段如图所示,其入口为顶点v1,出口为顶点v8,每条弧段旁的数字表示通过该路段所需时间,每次转弯需要附加时间为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实验结果:v1到v8的最短时间路径为15,路径为1-2-4-7-8.2、求如图所示中每一结点到其他结点的最短路。 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)实验结果: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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 七一活动合同范本
- 焊接包工合同范本
- 提高仓库应对突发事件的能力计划
- 促进学生团队合作能力的培养计划
- 《公司战略与风险管理》第3版 课件全套 吕文栋 第1-9章 战略与战略管理- 公司治理与战略管理、风险管理
- 城市房屋拆迁便民手册
- 2018年下半年企业人力资源管理师(三级)《理论知识》试题(网友回忆版)
- SMP-06-006-00 批记录管理规程
- 七年级历史上册 第四单元 第16课 三国鼎立教案 新人教版
- 六年级品德与社会下册 第一单元 生命需要呵护 第1课《生命的奥秘》教案 粤教版
- 东湖街道房屋租赁合同范本
- 【高中物理】光的折射+课件+高二上学期物理人教版(2019)选择性必修第一册+
- 2023学年完整公开课版望大陆
- 六年级数学上册第三单元例工程问题
- 奔驰汽车介绍PPT
- 普速铁路道口大修作业指导书
- 心理投影生幻觉注重心理描写和幻觉
- 城市规划原理课件-经济与产业
- 单片机理论题库(有答案)
- GB/T 18916.3-2002取水定额第3部分:石油炼制
- 冷链食品GMP培训试题及答案
评论
0/150
提交评论