一、简介

元胞自动机(CA)是一种用来仿真局部规则和局部联系的方法。典型的元胞自动机是定义在网格上的,每一个点上的网格代表一个元胞与一种有限的状态。变化规则适用于每一个元胞并且同时进行。典型的变化规则,决定于元胞的状态,以及其( 4 或 8 )邻居的状态。
1 对元胞自动机的初步认识
元胞自动机(CA)是一种用来仿真局部规则和局部联系的方法。典型的元
胞自动机是定义在网格上的,每一个点上的网格代表一个元胞与一种有限的状
态。变化规则适用于每一个元胞并且同时进行。
2 元胞的变化规则&元胞状态
典型的变化规则,决定于元胞的状态,以及其( 4 或 8 )邻居的状态。
3 元胞自动机的应用
元胞自动机已被应用于物理模拟,生物模拟等领域。
4 元胞自动机的matlab编程
结合以上,我们可以理解元胞自动机仿真需要理解三点。一是元胞,在matlab中可以理解为矩阵中的一点或多点组成的方形块,一般我们用矩阵中的一点代表一个元胞。二是变化规则,元胞的变化规则决定元胞下一刻的状态。三是元胞的状态,元胞的状态是自定义的,通常是对立的状态,比如生物的存活状态或死亡状态,红灯或绿灯,该点有障碍物或者没有障碍物等等。

二、源代码

% main.m
%
% This is a main script to simulate the approach, service, and departure of
% vehicles passing through a toll plaza, , as governed by the parameters
% defined below
%
%   iterations      =  the maximal iterations of simulation
%   B               =  number booths
%   L               =  number lanes in highway before and after plaza
%   Arrival         =  the mean total number of cars that arrives
%   plazalength     =  length of the plaza
%   Service         =  Service rate of booth
%   plaza           =  plaza matrix
%                      1 = car, 0 = empty, -1 = forbid, -3 = empty&booth
%   v               =  velocity matrix
%   vmax            =  max speed of car
%   time            =  time matrix, to trace the time that the car cost to
%                      pass the plaza.
%   dt              =  time step
%   t_h             =  time factor
%   departurescount =  number of cars that departure the plaza in the step
%   departurestime  =  time cost of the departure cars
%   influx          =  influx vector
%   outflux         =  outflux vector
%   timecost        =  time cost of all car
%   h               =  handle of the graphics
%
% zhou lvwen: zhou.lv.wen@gmail.comclear;clc
iterations = 1200; % the maximal iterations of simulation
B = 3; % number booths
L = 3; % number lanes in highway before and after plaza
Arrival=3; % the mean total number of cars that arrives plazalength = 81; % length of the plaza
[plaza, v, time,buspla] = create_plaza(B, L, plazalength);
h = show_plaza(plaza,buspla, NaN, 0.01);timeblock=5;
dt = 0.2; % time step
t_h = 1; % time factor
vmax = 2; % max speed
vinit=1;%initial speedbusstop=6*ones(plazalength,B+2);
carstop=3*ones(plazalength,B+2);timecost = [];
sf=0;%switchflag
for i = 1:iterationsif i==14ss=0;endif i==370ss=0;endfunction [plaza, v, time,buspla] = move_forward(plaza, v, time, vmax,buspla)
%
% move_forward   car move forward governed by NS algorithm:
%
% 1. Acceleration. If the vehicle can speed up without hitting the speed limit
% vmax it will add one to its velocity, vn -> vn + 1. Otherwise, the vehicle
% has constant speed, vn -> vn .
%
% 2. Collision prevention. If the distance between the vehicle and the car ahead
% of it, dn , is less than or equal to vn , i.e. the nth vehicle will collide
% if it doesn鈥檛 slow down, then vn -> dn 鈭?1.
%
% 3. Random slowing. Vehicles often slow for non-traffic reasons (cell phones,
% coffee mugs, even laptops) and drivers occasionally make irrational choices.
% With some probability pbrake , vn -> vn 鈭?1, presuming vn > 0.
%
% 4. Vehicle movement. The vehicles are deterministically moved by their velocities,
% xn -> xn + vn.
%
% USAGE: [plaza, v, time] = move_forward(plaza, v, time, vmax)
%        plaza = plaza matrix
%                1 = car, 0 = empty, -1 = forbid, -3 = empty&booth
%        v = velocity matrix
%        time = time matrix, to trace the time that the car cost to pass the plaza.
%        vmax = max speed of car
%
% zhou lvwen: zhou.lv.wen@gmail.comService = 0.8; % Service rate
dt = 0.2; % time step% Prob acceleration
probac = 0.7;
% Prob deceleration
probdc = 1;
% Prob of random deceleration
probrd = 0.3;
t_h = 1; % time factor[L,W] = size(plaza);
%bus
% b=find(plaza==-3);
% bf=b(find(plaza(b-1)==-3));
% for i=2:length(bf)
%     if bf(i)-bf(i-1)==1
%         for k=i:length(bf)-1
%             bf(k)=bf(k+1);
%         end
%     end
% % end
% bb=bf-1;% for i=1:length(bf)
% if plaza(bf(i)+1)==0
% if bf~=404&bf~=303
%    %no crushing
%    if plaza(bf(i)+1)==0
%         plaza(bf(i)+1)=-3;
%         plaza(bb(i))=0;
%         v(bf(i)+1)=v(bf(i));
%         v(bb(i)+1)=v(bb(i));
%    end
%    if plaza(bf(i)+1)~=0&&plaza((bf(i))-L)==0&&plaza((bb(i))-L)==0
%         plaza(bf(i))=0;
%         plaza(bb(i))=0;
%         plaza(bf(i)-L)=-3;
%         plaza(bb(i)-L)=-3;
%         v(bf(i))=0;
%         v(bb(i))=0;
%         v(bf(i)-L)=0;
%         v(bb(i)-L)=0;
%    elseif plaza(bf(i)-L)~=0&(plaza(bf(i)+1)==1|plaza(bf(i)+1)==-3|plaza(bf(i)+1)==-1)
%         v(bf(i))=0;
%         v(bb(i))=0;
%    end
% else
% plaza(b(bf))=0;
% plaza(b(bb))=0;
% v(b(bf))=0;
% v(b(bb))=0;
% end
% end
% end% gap measurement for car in (i,j)
gap = zeros(L,W);
f=find(plaza==1);for k=1:length(f)d = plaza(:,ceil(f(k)/(L)));gap(f(k)) = min(find([d(rem(f(k),L)+1:end)~=0;1]))-1;
end
gap(end,:) = 0;% update rules for speed:
% 1 Speed up, provided room
k = find((gap(f) > v(f)*t_h) & (v(f) + 1 <= vmax) & (rand(size(f)) <= probac));
v(f(k)) = v(f(k)) + 1;
% 2 No crashing
k = find((v(f)*t_h >(gap(f))) & (rand(size(f)) <= probdc));
for i=1:length(k)
if buspla(f(k(i)))~=2&&f(k(i))~=161&&f(k(i))~=242&&f(k(i))~=343
v(f(k))=gap(f(k));
end
end
% 3 Random decel
k = find((gap(f)<1) & (rand(size(f)) <= probdc));
for i=1:length(k)
if buspla(f(k(i)))~=2
v(f(k))=max(v(f(k)) - 1,0);
end
end

三、运行结果

【元胞自动机】基于元胞自动机模拟交通事故道路通行量matlab源码相关推荐

  1. 【元胞自动机】元胞自动机模拟交通事故道路通行量【含Matlab源码 356期】

    ⛄一.元胞自动机简介 1 元胞自动机发展历程 最初的元胞自动机是由冯 · 诺依曼在 1950 年代为模拟生物 细胞的自我复制而提出的. 但是并未受到学术界重视. 1970 年, 剑桥大学的约翰 · 何 ...

  2. 【物理应用】基于matlab模拟井筒多相流【含Matlab源码 2152期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[物理应用]基于matlab模拟井筒多相流[含Matlab源码 2152期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: 付 ...

  3. 【光学】基于matlab模拟拉盖尔高斯【含Matlab源码 2167期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab模拟拉盖尔高斯[含Matlab源码 2167期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: 付费专 ...

  4. 【优化求解】基于粒子群算法求解多目标优化问题matlab源码

    [优化求解]基于粒子群算法求解多目标优化问题matlab源码 1 算法介绍 1.1 关于速度和位置 粒子群算法通过设计一种无质量的粒子来模拟鸟群中的鸟,粒子仅具有两个属性:速度和位置,速度代表移动的快 ...

  5. matlab resampc函数,基于contourlet变换的红外与可见光图像融合matlab源码

    基于contourlet变换的红外与可见光图像融合matlab源码 matlab 2020-12-1 下载地址 https://www.codedown123.com/53619.html 基于con ...

  6. 信号检测:基于双稳随机共振的微弱信号检测含Matlab源码

    信号检测:基于双稳随机共振的微弱信号检测含Matlab源码 双稳随机共振是一种有效的微弱信号检测方法,广泛应用于各个领域.本文将介绍如何使用Matlab实现基于双稳随机共振的微弱信号检测,并提供相应的 ...

  7. 【元胞自动机】基于元胞自动机模拟双通道人群疏散含Matlab源码

    1 简介 为了消除礼堂的安全隐患,制定行之有效的应急预案,有必要对礼堂人群疏散运动进行研究,掌握礼堂人群疏散的一般特点和规律.采用基于二维元胞自动机模型对某高校礼堂发生人群疏散运动进行仿真,找出影响礼 ...

  8. 【布局优化】基于布谷鸟算法实现无线传感器网(WSN)覆盖优化 Matlab源码

    一.WSN模型 1.1 动机 近年来,随着对等网络.云计算和网格计算等分布式环境的发展,无线传感器网络(WSN)得到了广泛的应用.无线传感器网络(WSN)是一种新兴的计算和网络模式,它可以被定义为一个 ...

  9. 【布局优化】基于蚁狮算法的无线传感器网(WSN)覆盖优化matlab源码

    一.WSN模型 1.1 动机 近年来,随着对等网络.云计算和网格计算等分布式环境的发展,无线传感器网络(WSN)得到了广泛的应用.无线传感器网络(WSN)是一种新兴的计算和网络模式,它可以被定义为一个 ...

最新文章

  1. Dorado用法与示例
  2. 华为软件编程规范和范例 可读性
  3. 转 wordpress搭建
  4. HTML areamap标签及在实际开发中的应用
  5. 定时器0工作方式2,定时1s
  6. allegro怎么设置孔的属性_两种在Allegro中增加过孔的方法
  7. 虚拟服务器怎么进去,怎么进入虚拟主机
  8. PHP面向对象处理请求,PHP面向对象之命令模式
  9. vsan 一台主机磁盘组全报错_分享VSAN磁盘无法识别的故障解决方法
  10. win10安装MySQL5.7教程,linux安装MySQL教程,SQLyog安装教程
  11. Ubuntu之安装拼音输入法
  12. 带三维团队半年的一点总结和想法
  13. 【IOI2018】【luoguP4898】 seats 排座位 (线段树)
  14. 微信订阅消息推送(记录)
  15. 【BZOJ-28921171】强袭作战大sz的游戏 权值线段树+单调队列+标记永久化+DP...
  16. c语言零基础入门(完整版)
  17. 【C++】结构体嵌套结构体
  18. 助力丽水市周安村“数字乡村”建设 ,复杂美区块链赋能农产品溯源营销
  19. 苹果x怎么关机_苹果12怎么关机 iPhone12关机方法汇总
  20. yshon对讲机如何调频率_对讲机设置LT6100设置频率的方法

热门文章

  1. 【微机原理作业】8086存储器读写实验
  2. 在c51语言中当while语句中条件,在C51语言中,当do-while语句中的条件为( )时,结束循环。...
  3. 网络资产中主机发现方案分析
  4. 安装虚拟机步骤 详细
  5. Nginx 连接限制和访问控制Nginx 连接限制和访问控制
  6. 修改多台远程服务器,电脑默认用户名Administrator
  7. 前沿科技赋能教育,掌门优课创新教学体验
  8. iphone有关QQ和微信无法收到推送通知的终极解决方案
  9. matlab 截断共轭梯度法,最优化作业 共轭梯度法 matlab代码
  10. 通过爬虫获取银行名称