dijkstra算法matlab(dijkstra算法matlab文件)
大家好!今天让创意岭的小编来大家介绍下关于dijkstra算法matlab的问题,以下是小编对此问题的归纳整理,让我们一起来看看吧。
开始之前先推荐一个非常厉害的Ai人工智能工具,一键生成原创文章、方案、文案、工作计划、工作报告、论文、代码、作文、做题和对话答疑等等
只需要输入关键词,就能返回你想要的内容,越精准,写出的就越详细,有微信小程序端、在线网页版、PC客户端
创意岭作为行业内优秀的企业,服务客户遍布全球各地,如需了解SEO相关业务请拨打电话175-8598-2043,或添加微信:1454722008
本文目录:
一、
二、求程序 在matlab上用Dijkstra和Floyd算法求出v1到v8的最短路径。。
function [ distance, path] = Dijkstra( W,st,e )n=length(W);
D = W(st,:);
visit= ones(1:n);
visit(st)=0;
parent = zeros(1,n);
path =[];
for i=1:n-1
temp = [];
for j=1:n
if visit(j)
temp =[temp D(j)];
else
temp =[temp inf];
end
end
[~,index] = min(temp);
visit(index) = 0;
for k=1:n
if D(k)>D(index)+W(index,k)
D(k) = D(index)+W(index,k);
parent(k) = index;
end
end
end
distance = D(e);
t = e;
while t~=st && t>0
path =[t,path];
p=parent(t);t=p;
end
path =[st,path];%最短路径
end
W = [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 Inf 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 ];
[distance,path]=Dijkstra(W,1,8);
>> distance
distance =
23
>> path
path =
1 2 4 5 7 8
三、
四、
以上就是关于dijkstra算法matlab相关问题的回答。希望能帮到你,如有更多相关问题,您也可以联系我们的客服进行咨询,客服也会为您讲解更多精彩的知识和内容。
推荐阅读:
增值电信业务许可证ICP和EDI(增值电信业务许可证和icp许可证)