数学建模社区-数学中国
标题:
这是图论模型的代码,用来求最短距离的,但是程序有点问题,一直没改对,希望大家...
[打印本页]
作者:
1522500748
时间:
2013-9-29 22:11
标题:
这是图论模型的代码,用来求最短距离的,但是程序有点问题,一直没改对,希望大家...
这是图论模型的代码,用来求最短距离的,但是程序有点问题,一直没改对,希望大家给帮下忙!
a=zeros(6);
a(1,2)=50;a(1,4)=40;a(1,5)=25;a(1,6)=10;
a(2,3)=15;a(2,4)=20;a(2,6)=25;
a(3,4)=10;a(3,5)=20;
a(4,5)=10;a(4,6)=25;
a(5,6)=55;
a=a+a';
a=find((a==0))=inf;
pb=(1:length(a))==0;pb(1)=1;index1=1;index2=ones(1,length(a));
d(1:length(a))=inf;d(1)=0;temp=1;
while sum(pb)<length(a);
tb=find(pb==0);
d(tb)=min(d(tb),d(temp)+a(temp,tb));
tmpb=find(d(tb)==min(d(tb)));
pb(temp)=1;
index1=[index1,temp];
temp2=find(d(index1)==d(temp)-a(temp,inde1));
index2(temp)=index1(temp2(1));
end
d,index1,index2
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5