资源简介
利用matlab进行元胞自动机仿真代码,欢迎下载参考!!

代码片段和文件信息
% Nagel Schreckenberg model simulation
%Written by Alexander Farley
%Feb 6 2012
%alexander.farley at utoronto.ca
%This script implements the Nagel Schreckenberg cellular automata based
%traffic model. Flow vs density curves are displayed.
%
%
%Update June 5 2012: Fixed problem in vehicle velocity updates
%Update Jan 13 2013: Fixed problem with vmax=1 showing no flow
%Update June 12 2013: Corrected calculation of flow rate for FD plot
%
%Parameters
vmax = 10;
p = 0.6;%原始数据0.8
road_length = 1000;
simulation_steps = 1000;
render_on = 0;
pause_on = 0;
delay_on = 0;
delay_length = 0.02; %10 FPS
road = zeros(1road_length); %Contains occupation state
road_next = road;
velocities = zeros(1road_length); %Contains velocity state
velocities_next = velocities;
%Sampling
num_samples = 2000;
samples = zeros(2num_samples); %Contains density and flow rate
density_step = 1/num_samples;
history = zeros(simulation_steps road_length);
velocity_history = zeros(simulation_steps road_length);
figure
for g=1:num_samples;
%Generate traffic
road = zeros(1road_length); %Contains occupation state
road_next = road;
density = g/num_samples;
%Generate traffic
for i=1:road_length
if rand < density
road(i) = 1;
end
end
if render_on
imshow(road);
drawnow
end
%Run simulation
for i=1:simulation_steps
history(i :) = road;
velocity_history(i:) = velocities;
%--------------------Velocity update ------------------------%
for j=1:road_length
if road(j) == 1
distance = 0;
%Seek vmax ahead
bf = 0;
for k=1:vmax
distance = k;
if j+k <= road_length %The index is the “cell under consideration“ - is it safe to land here?
index = j+k;
else
index = j+k-road_length; %Deal with wrapping
end
if road(index) == 1
bf = 1;
end
if bf == 1 break end
end
if velocities(j) < vmax %Acceleration
velocities(j) = velocities(j) + 1;
end
if (velocities(j) > distance - 1) && bf == 1 %Collision avoidance
velocities(j) = distance - 1;
end
if rand < p && velocities(j) > 0 %Random braking
velocities(j) = velocities(j) - 1;
end
end
end
%--------------------Movement -------------------------------%
for j=1:ro
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4340 2016-06-27 17:16 NaSchr.m
文件 340 2016-06-27 17:14 ts.m
----------- --------- ---------- ----- ----
4680 2
相关资源
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
- 神经网络分类matlab程序
- matlab正弦信号发生器的设计
- matlab程序用Hopfield网络解决TSP
评论
共有 条评论