【元胞自动机】基于元胞自动机实现双车道靠右行驶交通流模型matlab代码

250 阅读1分钟

1 简介

元胞自动机(Cellular Automata,简称CA)模型作为交通流理论的一种重要数学模型,具有时空离散、规则简单、计算效率高、易于实现等特点,一直都是交通流研究的一个热点,具有广阔应用前景。本文在现有元胞自动机交通流模型的基础上,建立双车道元胞自动机交通流模型。

2 部分代码

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A Two-Lane Cellular Automaton Traffic Flow Model with the Keep-Right Rule
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all;
close all;

B=3;              % The number of the lanes
plazalength=100;  % The length of the simulation highways
h=NaN;            % The handle of the image


[plaza,v]=create_plaza(B,plazalength);
h=show_plaza(plaza,h,0.1);

iterations=1000;    % Number of iterations
probc=0.1;          % Density of the cars
probv=[0.1 1];      % Density of two kinds of cars
probslow=0.3;       % The probability of random slow
Dsafe=1;            % The safe gap distance for the car to change the lane
VTypes=[1,2];       % Maximum speed of two different cars 
[plaza,v,vmax]=new_cars(plaza,v,probc,probv,VTypes);% Generate cars on the lane

size(find(plaza==1))
PLAZA=rot90(plaza,2);
h=show_plaza(PLAZA,h,0.1);
for t=1:iterations;
   size(find(plaza==1))
   PLAZA=rot90(plaza,2);
   h=show_plaza(PLAZA,h,0.1);%%地图显示
  [v,gap,LUP,LDOWN]=para_count(plaza,v,vmax);
  [plaza,v,vmax]=switch_lane(plaza,v,vmax,gap,LUP,LDOWN);
  [plaza,v,vmax]=random_slow(plaza,v,vmax,probslow);
  [plaza,v,vmax]=move_forward(plaza,v,vmax);
end

3 真结果

4 参考文献

[1]李松, 张杰, 贺国光. 基于元胞自动机模型的交通流混沌仿真研究[J]. 计算机工程与应用, 2007, 43(32):4.

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