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

1 简介

为了消除礼堂的安全隐患,制定行之有效的应急预案,有必要对礼堂人群疏散运动进行研究,掌握礼堂人群疏散的一般特点和规律。采用基于二维元胞自动机模型对某高校礼堂发生人群疏散运动进行仿真,找出影响礼堂人群疏散效率的关键因素,为高校礼堂设计提供支持;为高校礼堂制定突发事件应急预案提供参考。​

2 部分代码

% 函数populate - 分配占用并随机填充% pedestrins, doors and obstacles% Occupied的初始化% 在The Seed里面,表面上将Doors定义为nDoors行2列的矩阵,实际上Doors是宽度行2列的矩阵。% 例如,只有一个宽度为7的横向的门,则Doors是7行2列的矩阵,每一行对应于门的一个cell。function [Occupied,Doors,Obstacles] = populate(population, gridDims)n = gridDims(1);                           % 房间的长m = gridDims(2);                           % 房间的宽% nDoors = paramsDoors(1);                   % nDoors = 2% lengths = paramsDoors(2);Occupied = zeros(n, m);                    % 将Occupied网格初始化为n*m的全为0的网格% 边界是被墙体占据的,绘制四面墙体Occupied(1,:) = 1;Occupied(n,:) = 1;Occupied(:,1) = 1;Occupied(:,m) = 1;% 门Doors=[23,50;24,50;25,50;26,50;27,50;28,50];for i=1:size(Doors)    Occupied(Doors(i,1),Doors(i,2))=0;end% 房间之间的墙体Occupied(21,:) = 100;Occupied(30,:) = 100;for i=2:21    Occupied(i,17) = 100;    Occupied(i,34) = 100;endfor i=30:49    Occupied(i,17) = 100;    Occupied(i,34) = 100;enda=7;b=24;c=40;for i=0:3                % 把循环次数改成 3 就可以让所有人都逃出了(消除了死角)    Occupied(21,a+i) = 0;    Occupied(21,b+i) = 0;    Occupied(21,c+i) = 0;        Occupied(30,a+i) = 0;    Occupied(30,b+i) = 0;    Occupied(30,c+i) = 0;end% Obstacles的坐标矩阵nObstacles=0;for i=2:n-1    for j=2:m-1        if Occupied(i,j)==100            nObstacles=nObstacles+1;            continue        end    endendObstacles=zeros(nObstacles,2);a=1;for i=2:n-1    for j=2:m-1        if Occupied(i,j)==100            Obstacles(a,1)=i;            Obstacles(a,2)=j;            a=a+1;        end    endend% populate after obstacles has been generated 在障碍物产生后填充(这一部分我移到calcStatField.m的最后面去了)populated=0;while(populated ~= population)                          % population 是在 evacuation 里面设置好的i = randi(n-2) + 1;                                     % 减去二是减去墙体占据的两格空间 j = randi(m-2) + 1;                                     % 随机取房间内的一个cellif(Occupied(i, j) == 0)Occupied(i, j) = 1;                                     % 这一整个while循环就是用来放人的!populated = populated + 1;                              % 我需要把这个步骤放在S场计算完之后。endend% % gen random doors% cnt = 1;% for i = 1: nDoors% event1 = rand(1);% event2 = rand(1);% % if(event1 <= 0.5)                         % vertical door% % id = randi(m-2 - lengths(i)) + 1;           % start y pos   这里的id是[2,48-随机宽度]之间的值% idI = 1;                                    % idI 是什么?% if(event2 > 0.5)                            % left or right wall% idI = n;                                    % 这是怎么靠这两个event来分左右墙的?% end% % for j = 0:lengths(i)-1                      % append in right direction% Occupied(idI, id+j) = 0;                    % 这个地方应该是在设置门这个区域的对应值吧% Doors(cnt,:) = [idI, id+j];% cnt = cnt + 1;% end% % else % horizontal door% % id = randi(n-2-lengths(i)) + 1;             % start x pos% idJ = 1;% if(event2 > 0.5)                            % bottom or up wall% idJ = m;% end% % for j = 0: lengths(i)-1                     % append in top direction% Occupied(id+j, idJ) = 0;% Doors(cnt,:) = [id+j, idJ];% cnt = cnt+1;% end% end% end% gen random obstacles% Obstacles = zeros(size(ObstacleLengths, 1), 2);% cnt = 1;% for i = 1: nObstacles% % event1 = rand(1);% if(event1 <= 0.33)                            % vertical obsracle% idJ = randi(m-4 - ObstacleLengths(i)) + 2;   % not to obstruct the door% idI = randi(n-4) + 2;                         % not to obstract the door% % for j = 0:ObstacleLengths(i)-1% if(Occupied(idI, idJ+j) ~= 0)% break;% end% Occupied(idI, idJ+j) = 100;% Obstacles(cnt,:) = [idI, idJ+j];% cnt = cnt + 1;% end% % elseif (event1 <=0.66)                        % horizontal obstacle 水平障碍% % idJ = randi(m-4) + 2;                         % not to obstuct the door 不阻碍门% idI = randi(m-4 - obstaclesLengths(i)) + 2;   % not to obstuct the door% % for j = 0:obstaclesLengths(i)-1% if(Occupied(idI+j, idJ) ~= 0)% break;% end% Occupied(idI+j, idJ) = 100;% Obstacles(cnt,:) = [idI+j, idJ];% cnt = cnt + 1;% end% else                                          % diagonal obstacle% % idJ = randi(m-4 - obstaclesLengths(i)) + 2;   % not to obstuct the door% idI = randi(m-4 - obstaclesLengths(i)) + 2;   % not to obstuct the door% % for j = 0:obstaclesLengths(i)-1% if(Occupied(idI+j, idJ+j) ~= 0)% break;% end% Occupied(idI+j, idJ+j) = 100;% Obstacles(cnt,:) = [idI+j, idJ+j];% cnt = cnt + 1;% end% end% end% % populate after obstacles has been generated 在障碍物产生后填充(这一部分我移到calcStatField.m的最后面去了)% while(populated ~= population)                          % population 是在 evacuation 里面设置好的% % i = randi(n-2) + 1;                                     % 减去二是减去墙体占据的两格空间 % j = randi(m-2) + 1;                                     % 随机取房间内的一个cell% % if(Occupied(i, j) == 0)% Occupied(i, j) = 1;                                     % 这一整个while循环就是用来放人的!% populated = populated + 1;                              % 我需要把这个步骤放在S场计算完之后。% end% endend

3 仿真结果

4 参考文献

[1]林煌涛等. "基于元胞自动机模型的礼堂人群疏散仿真." 现代计算机 (2013).

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

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

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值