clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
N=15;
MaxDist = 40;
rand('seed',69);
INF = 10000;
x=randi([10,90],1,N);%Setups up random nodes
y=randi([10,90],1,N);
x(1)=0;
y(1)=0;
x(N)=100;
y(N)=100;
short=ones(2,N);
DistMat = [];
for i=1:N
short(2,i) = INF; %sets the shortest length to this node %at the start all nodes are in respect to 1
for j=1:N
DistMat(i,j) = sqrt((x(i)-x(j))^2+(y(i)-y(j))^2);
if DistMat(i,j)>MaxDist
DistMat(i,j)=INF;%infinite
end
end
end
short(2,1) = 0; %node 1 distance is 0
fig = figure
plot(x(2:N-1),y(2:N-1),'o','markersize',6,'markerfacecolor','k');%Circles
hold on;
plot([x(1) x(N)],[y(1) y(N)],'s','markersize',6,'markerfacecolor','b');%End square
grid on;
for i=1:N
text(x(i),y(i)+5,strcat('N',num2str(i)));%node names
end
Aval=[1:N]%all avalible nodes
Done=[];%holds nodes already visited
for t=1:N
shortest = INF+1;%resets the longest distance
if(t==1)%start at node 1
Cnode = 1;
else
for k=2:N
if(~ismember(k,Done) && shortest>short(2,k))%if not already finished
Cnode = k; %select the shortest path
shortest = short(2,k);
end
end
end
Done(1,t)=Cnode;
Aval = setdiff(Aval,[Cnode]); %strip current node from avalable
for j=1:length(Aval)
if (DistMat(Cnode,Aval(j))<MaxDist)%checks if jump is resonable
if(1==1)
if(DistMat(Cnode,Aval(j))+short(2,Cnode)<short(2,Aval(j)))%checks and sees if new path is shorter
short(2,Aval(j)) = DistMat(Cnode,Aval(j))+short(2,Cnode);%new distance
short(1,Aval(j)) = Cnode; %new base node
if(short(2,Aval(j))<shortest) %if its the shortest set it as the shortest
shortest = short(2,Aval(j));
end
end
end
end
end
for i=2:N%prints out the current minimum distance to each node
if(short(2,(i))<INF)%only print if distnace isn't infinite
plots(i) = plot([x((i));x(short(1,(i)))],[y((i));y(short(1,(i)))],'linewidth',1.5)
plotst(i) = text((x((i))+x(short(1,(i))))/2,(y((i))+y(short(1,(i))))/2-5,num2str(short(2,(i))));
end
end
%saveas(fig,num2str(t),'png')
pause(1);
for i=2:N%clears previous nodes.
if(short(2,(i))<INF)%only delete drawn ones
delete(plots(i));
delete(plotst(i));
end
end
end
pause(5);
i = N;%last node
while(i ~= 1)%first node
if(short(2,i)<INF)%only print if distnace isn't infinite
plots(i) = plot([x(i);x(short(1,i))],[y(i);y(short(1,i))],'linewidth',1.5)
text((x(i)+x(short(1,i)))/2,(y(i)+y(short(1,i)))/2-5,num2str(short(2,i)));
i = short(1,i);
pause(1);
end
end
pause(1);
没有合适的资源?快使用搜索试试~ 我知道了~
基于Dijkstra算法的网络路由最短路径matlab仿真+仿真操作录像
共2个文件
avi:1个
m:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 3 下载量 156 浏览量
2022-10-17
03:31:49
上传
评论 5
收藏 129KB RAR 举报
温馨提示
1.版本:matlab2021a,我录制了仿真操作录像,可以跟着操作出仿真结果 2.领域:Dijkstra算法 3.内容:基于Dijkstra算法的网络路由最短路径matlab仿真,动态显示Dijkstra算法搜索路径的过程 4.适合人群:本,硕等教研学习使用
资源推荐
资源详情
资源评论
收起资源包目录
基于Dijkstra算法的网络路由最短路径matlab仿真,动态显示Dijkstra算法搜索路径的过程.rar (2个子文件)
基于Dijkstra算法的网络路由最短路径matlab仿真,动态显示Dijkstra算法搜索路径的过程
操作录像0031.avi 6.17MB
Runme.m 3KB
共 2 条
- 1
资源评论
- 巧克力6722024-03-15总算找到了想要的资源,搞定遇到的大问题,赞赞赞!
- weixin_456954392022-12-21资源不错,很实用,内容全面,介绍详细,很好用,谢谢分享。
- m0_720672412024-04-24资源是宝藏资源,实用也是真的实用,感谢大佬分享~
fpga和matlab
- 粉丝: 15w+
- 资源: 2548
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功