clf
clear
%build the GUI
%define the plot button
plotbutton=uicontrol('style','pushbutton',...
'string','Run', ...
'fontsize',12, ...
'position',[100,400,50,20], ...
'callback','run=1;');
%define the stop button
erasebutton=uicontrol('style','pushbutton',...
'string','Stop', ...
'fontsize',12, ...
'position',[200,400,50,20], ...
'callback','freeze=1;');
%define the Quit button
quitbutton=uicontrol('style','pushbutton',...
'string','Quit', ...
'fontsize',12, ...
'position',[300,400,50,20], ...
'callback','stop=1;close;');
number = uicontrol('style','text', ...
'string','1', ...
'fontsize',12, ...
'position',[20,400,50,20]);
n = 100; %数据初始化
z=zeros(1,n); %元胞个数
z=roadstart(z,5); %道路状态初始化,路段上随机分布5辆
cells=z;
vmax=3; %最大速度
v=speedstart(cells,vmax); %速度初始化
x=1; %记录速度和车辆位置
memor_cells=zeros(3600,n);
memor_v=zeros(3600,n);
imh=imshow(cells);
%初始化图像白色有车,黑色空元胞
set(imh,'erasemode','none')
axis equal
axis tight
stop=0;%wait for a quit button push
run=0; %wait for a draw
freeze=0; %wait for a freeze(冻结)
while (stop==0)
if(run==1)
%边界条件处理,搜素首末车,控制进出,使用开口条件
a=searchleadcar(cells);
b=searchlastcar(cells);
[cells,v]=border_control(cells,a,b,v,vmax);
i=searchleadcar(cells); %搜索首车位置
for j=1:i
if i-j+1==n
[z,v]=leadcarupdate(z,v);
continue;
else
%======================================加速、减速、随机慢化
if cells(i-j+1)==0; %判断当前位置是否非空
continue;
else
v(i-j+1)=min(v(i-j+1)+1,vmax); %加速
%=================================减速
k=searchfrontcar((i-j+1),cells); %搜素前方首个非空元胞位置
if k==0; %确定于前车之间的元胞数
d=n-(i-j+1);
else d=k-(i-j+1)-1;
end
v(i-j+1)=min(v(i-j+1),d);
%==============================%减速
%随机慢化
v(i-j+1)=randslow(v(i-j+1));
new_v=v(i-j+1);
%======================================加速、减速、随机慢化
%更新车辆位置
z(i-j+1)=0;
z(i-j+1+new_v)=1;
%更新速度
v(i-j+1)=0;
v(i-j+1+new_v)=new_v;
end
end
end
cells=z;
memor_cells(x,:)=cells; %记录速度和车辆位置
memor_v(x,:)=v;
x=x+1;
set(imh,'cdata',cells) %更新图像
%update the step number diaplay
pause(0.2);
stepnumber = 1 + str2num(get(number,'string'));
set(number,'string',num2str(stepnumber))
end
if(freeze==1)
run = 0;
freeze = 0
end
drawnow
end
NA modal MATLAB code.rar_MATLAB交通_交通模型_交通流_交通流matlab_交通流模型
版权申诉
28 浏览量
2022-07-14
17:48:50
上传
评论 1
收藏 4KB RAR 举报
朱moyimi
- 粉丝: 65
- 资源: 1万+
最新资源
- Java课设相关材料.zip
- JSP搜索引擎的研究与实现(源代码)
- delphi 12 控件之delphipi.0.85.setup.exe
- 数据库管理工具:dbeaver-ce-23.0.2-amd64.deb
- 搜索链接淘特搜索引擎共享版-tot-search-engine
- 数据库管理工具:dbeaver-ce-24.0.3-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-24.0.1-x86-64-setup.exe
- GoogleCloud2024年数据和AI趋势报告+生成式AI+数据治理
- delphi 12 控件之EhLib 11.0.21 - D12.7z
- 基于JAVA+VUE的论坛网站
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈