首页 > 行业资讯 > 【元胞自动机】基于元胞自动机实现交通流NaSch模型matlab源码

【元胞自动机】基于元胞自动机实现交通流NaSch模型matlab源码

时间:2022-02-23 来源: 浏览:

【元胞自动机】基于元胞自动机实现交通流NaSch模型matlab源码

天天Matlab 天天Matlab
天天Matlab

TT_Matlab

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,完整matlab代码或者程序定制加qq1575304183。

收录于话题 #元胞自动机应用matlab源码 34个

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代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

版权:如无特殊注明,文章转载自网络,侵权请联系cnmhg168#163.com删除!文件均为网友上传,仅供研究和学习使用,务必24小时内删除。
相关推荐