【元胞自动机】基于元胞自动机实现交通流NaSch模型matlab源码
【元胞自动机】基于元胞自动机实现交通流NaSch模型matlab源码
TT_Matlab
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,完整matlab代码或者程序定制加qq1575304183。
1 简介
NaSch 模型是由最初出版于 1992 年的 Kai Nagel 和 Michael Schreckenberg [30] 的先前工 作中提出的,在其论文中汽车被放置成一维阵列,其中每个元胞可以被占用或未被占用, 并且汽车在每个占用的元胞中的速度被设定为零和指定的系统最大速度之间随机速度。多 辆汽车不可能占用相同的元胞,并且该模型的每次迭代由同时发生的四个基本操作控制。 这四个步骤是:
2 部分代码
% 主程序:NaSch_3.m程序代码
% 单车道最大速度
3
个元胞开口边界条件加速减速随机慢化
clf
clear all
%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’
,[
100
,
500
,
50
,
20
], ...
’callback’
,
’freeze=1;’
);
%define the Quit button
quitbutton=uicontrol(
’style’
,
’pushbutton’
,...
’string’
,
’Quit’
, ...
’fontsize’
,
12
, ...
’position’
,[
100
,
600
,
50
,
20
], ...
’callback’
,
’stop=1;close;’
);
number = uicontrol(
’style’
,
’text’
, ...
’string’
,
’1’
, ...
’fontsize’
,
12
, ...
’position’
,[
20
,
400
,
50
,
20
]);
%CA setup
n=
1000
; %数据初始化
z=zeros(
1
,n); %元胞个数
z=roadstart(z,
200
); %道路状态初始化,路段上随机分布
200
辆
cells=z;
vmax=
5
; %最大速度
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.0001
)
;
stepnumber =
1
+str2num(
get
(number,
’string’
));
set
(number,
’string’
,num2str(stepnumber))
end
if
(
freeze==
1
)
run
=
0
;
freeze =
0
;
end
drawnow
end
%% NaSch时空图
figure(
1
)
set
(gcf,
’outerposition’
,
get
(
0
,
’screensize’
));
for
l=
1
:
1
:
3600
for
k=
1
:
1
:
1000
if
memor_cells
(
l,k
)> 0
plot
(
k,l,
’k.’
)
;
hold
on
;
end
end
end
xlabel
(
’空间位置 ’
)
ylabel
(
’时间(s)’
)
set
(
gca,
’FontSize’
,
24
,
’Fontname’
,
’Times New Roman’
)
;
set
(
get
(gca,
’XLabel’
),
’Fontsize’
,
24
,
’Fontname’
,
’宋体’
);
set
(
get
(gca,
’YLabel’
),
’Fontsize’
,
24
,
’Fontname’
,
’宋体’
);
set
(gca,
’looseInset’
,[
0
0
0
0
]);
print(
1
,
’-dpng’
,
’-r300’
,
’NaSch时空图’
);
%% NaSch密度流量图
figure(
2
)
set
(gcf,
’outerposition’
,
get
(
0
,
’screensize’
));
for
i=
1
:
1
:
500
density(i)=sum(memor_cells(i,:)>
0
)/
1000
;
flow(i)=sum(memor_v(i,:))/
1000
;
end
h= plot(density,flow,
’k.’
);
set
(h,
’MarkerSize’
,
20
);
%title(
’流量密度图 ’
)
xlabel(
’车流密度’
)
ylabel(
’车流速度’
)
set
(gca,
’FontSize’
,
24
,
’Fontname’
,
’Times New Roman’
);
set
(
get
(gca,
’XLabel’
),
’Fontsize’
,
24
,
’Fontname’
,
’宋体’
);
set
(
get
(gca,
’YLabel’
),
’Fontsize’
,
24
,
’Fontname’
,
’宋体’
);
set
(gca,
’looseInset’
,[
0
0
0
0
]);
print(
2
,
’-dpng’
,
’-r300’
,
’NaSch密度流量图’
);
3 仿真结果
4 参考文献
[1]李伟娟. (2015). 基于元胞自动机的城市车辆换道模型仿真研究. 吉林大学.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
-
2023年血糖新标准公布,不是3.9-6.1,快来看看你的血糖正常吗? 2023-02-07
-
2023年各省最新电价一览!8省中午执行谷段电价! 2023-01-03
-
GB 55009-2021《燃气工程项目规范》(含条文说明),2022年1月1日起实施 2021-11-07
-
PPT导出高分辨率图片的四种方法 2022-09-22
-
2023年最新!国家电网27家省级电力公司负责人大盘点 2023-03-14
-
全国消防救援总队主官及简历(2023.2) 2023-02-10
-
盘点 l 中国石油大庆油田现任领导班子 2023-02-28
-
我们的前辈!历届全国工程勘察设计大师完整名单! 2022-11-18
-
关于某送变电公司“4·22”人身死亡事故的快报 2022-04-26
