1
2014
美赛相关
MATLAB
程序(基?/p>
NS
模型?/p>
主程序:
NaSch_3.m
程序代码
%
单车?/p>
最大速度
3
个元?/p>
开口边界条?/p>
加?/p>
减?/p>
随机慢化
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',[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]);
%CA setup
n=100; %
数据初始?/p>
z=zeros(1,n); %
元胞个数
z=roadstart(z,5); %
道路状态初始化,路段上随机分布
5
?/p>
cells=z;
vmax=3; %
最大速度
v=speedstart(cells,vmax); %
速度初始?/p>
x=1; %
记录速度和车辆位?/p>
memor_cells=zeros(3600,n);
memor_v=zeros(3600,n);
imh=imshow(cells); %
初始化图像白色有车,黑色空元?/p>
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)
%
边界条件处理,搜素首末车,控制进出,使用开口条?/p>
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);