《用matlab软件求最短路实例2》由会员分享,可在线阅读,更多相关《用matlab软件求最短路实例2(6页珍藏版)》请在金锄头文库上搜索。
1、用用 MATLAB 软软件求最短路件求最短路实实例例 2试用 MATLAB 软件计算有向图中 v1 到 v9 的最短路。v9v1v2v3v4v5v6v7v8333331 1222445运筹学课程设计实验报告 06 信息管理与信息系统(中美合作) 顾真皓 06130801322解:解:w=ones(9);w=inf*w; for i=1:9w(i,i)=0;end w(1,2)=3;w(1,4)=4; w(2,3)=3;w(2,5)=2;w(2,6)=3; w(3,9)=5; w(4,7)=3; w(5,6)=3; w(6,9)=1;w(6,7)=1; w(7,8)=2;w(7,9)=2; w(
2、8,9)=4; p=log(8)/log(2) %向上(大的方向)取整向上(大的方向)取整p =3 w1=w运筹学课程设计实验报告 06 信息管理与信息系统(中美合作) 顾真皓 06130801323w1 =0 3 Inf 4 Inf Inf Inf Inf InfInf 0 3 Inf 2 3 Inf Inf InfInf Inf 0 Inf Inf Inf Inf Inf 5Inf Inf Inf 0 Inf Inf 3 Inf InfInf Inf Inf Inf 0 3 Inf Inf InfInf Inf Inf Inf Inf 0 1 Inf 1Inf Inf Inf Inf In
3、f Inf 0 2 2Inf Inf Inf Inf Inf Inf Inf 0 4Inf Inf Inf Inf Inf Inf Inf Inf 0 w2=fld(9,w)w2 =0 3 6 4 5 6 7 Inf InfInf 0 3 Inf 2 3 4 Inf 4Inf Inf 0 Inf Inf Inf Inf Inf 5Inf Inf Inf 0 Inf Inf 3 5 5Inf Inf Inf Inf 0 3 4 Inf 4Inf Inf Inf Inf Inf 0 1 3 1运筹学课程设计实验报告 06 信息管理与信息系统(中美合作) 顾真皓 06130801324Inf Inf
4、 Inf Inf Inf Inf 0 2 2Inf Inf Inf Inf Inf Inf Inf 0 4Inf Inf Inf Inf Inf Inf Inf Inf 0 w3=fld(9,w2)w3 =0 3 6 4 5 6 7 9 7Inf 0 3 Inf 2 3 4 6 4Inf Inf 0 Inf Inf Inf Inf Inf 5Inf Inf Inf 0 Inf Inf 3 5 5Inf Inf Inf Inf 0 3 4 6 4Inf Inf Inf Inf Inf 0 1 3 1Inf Inf Inf Inf Inf Inf 0 2 2Inf Inf Inf Inf Inf
5、Inf Inf 0 4Inf Inf Inf Inf Inf Inf Inf Inf 0functionci,cj,dij=stlin(n,i,j,d) %求最短路的路径求最短路的路径 ci=d(i,j)-d(i,:);cj=d(:,j);dij=d(i,j);function y=fld(n,x) %求最短路求最短路 for r=1:n运筹学课程设计实验报告 06 信息管理与信息系统(中美合作) 顾真皓 06130801325for i=1:nfor j=1:np(j)=x(i,j)+x(j,r);endy(r,i)=min(p);endend c1,c9,d19=stlin(9,1,9,w3)c1 =7 4 1 3 2 1 0 -2 0运筹学课程设计实验报告 06 信息管理与信息系统(中美合作) 顾真皓 06130801326c9 =745541240d19 =7