当前位置 : 主页 > 编程语言 > python >

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

来源:互联网 收集:自由互联 发布时间:2022-06-18
1 简介 为了消除礼堂的安全隐患,制定行之有效的应急预案,有必要对礼堂人群疏散运动进行研究,掌握礼堂人群疏散的一般特点和规律。采用基于二维元胞自动机模型对某高校礼堂发生人

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;
end
for i=30:49
Occupied(i,17) = 100;
Occupied(i,34) = 100;
end
a=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
end
end
Obstacles=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
end
end
% 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; % 随机取房间内的一个cell
if(Occupied(i, j) == 0)
Occupied(i, j) = 1; % 这一整个while循环就是用来放人的!
populated = populated + 1; % 我需要把这个步骤放在S场计算完之后。
end
end
% % 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
% end
end

3 仿真结果

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

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

4 参考文献

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

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

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

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





网友评论