云南大学软件学院计算机网络原理报(2).docx
《云南大学软件学院计算机网络原理报(2).docx》由会员分享,可在线阅读,更多相关《云南大学软件学院计算机网络原理报(2).docx(6页珍藏版)》请在三一办公上搜索。
1、云南大学软件学院计算机网络原理报实验八、Link States Algorithm的实现 序号: 姓名: _ 学号: _ 成绩 指导老师: 刘宇 刘春花 1实验目的: 通过编程模拟实现LSA. 2实验环境: VS.net软件开发平台,可以使用任何编程语言。 3实验要求 求网络中任何两个结点之间的最短路径。 得到任何一个节点上的转发表。 实验内容、拓扑结构 Initialization: 2 N = u /*u is source node*/ 3 for all nodes j /* j is dest node*/ 4 if j adjacent to u 5 then D(j) = c(u
2、,j) 6 else D(j) = 7 8 Loop 9 find i not in N such that D(i) is a minimum 10 add i to N 11 update D(j) for all j adjacent to i and not in N : 12 D(j) = min( D(j), D(i) + c(i,j) ) 13 /* new cost to j is either old cost to j or known 14 shortest path cost to i plus cost from i to j */ 15 until all node
3、s in N 程序: #include #include #define INFINITY 10000 /最大距离 #define MAX_NODES 50 /最大节点数 int distMAX_NODESMAX_NODES; /distij表示从 i 到 j 的距离 int pathMAX_NODES; typedef struct int vexnum; int vexMAX_NODES; graph; void init_graph(graph *g) int a,x,y=0; g-vexnum = 5; for(a =0;avexnum;a+) g-vexa=a; for(x=0;xv
4、exnum;x+) for(y=0;yvexnum;y+) distxy=INFINITY; dist01 = 7;dist04 = 1; dist10 = 7;dist12 = 1; dist14 = 8;dist21 = 1; dist23 = 2;dist32 = 2; dist34 = 2;dist40 = 1; dist41 = 8;dist43 = 2; void shortest_path(int s, int t,int n) struct state int predecessor; /前驱节点 int length; /到起始点的距离 int label; stateMAX
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 云南大学 软件 学院 计算机网络 原理

链接地址:https://www.31ppt.com/p-3235728.html