1 简介
从分析传染病的传播和发展的规律出发,利用元胞自动机构造出传染病传播和控制的仿真模型,同时引入隔离和预防策略对元胞演化制定了相应的规则,依据这些规则对每个元胞进行了同步更新.运用建立的元胞自动机模型对传染病传播和控制过程中所发生的变化进行有效模拟,同时给出了模型核心部分的matlab程序代码.模拟和分析结果表明,元胞自动机模型应用于传染病传播的模拟是合理的有效的,并进一步验证了接种疫苗,隔离,医学治疗是预防疾病和阻断疾病传播的有效手段.建立的元胞自动机模型还可运用到经济投资模拟,污染扩散等领域,具有很广阔的应用前景.
2 部分代码
%% NOTE
% Total runtime for this code was about 1-3 minutes on the personal
% computer used by the original researcher
% This runtime is expected to vary from device to device, and is being used
% here to obtain a general comparison for runtime for the different
% models. It is not for a universal runtime value
%% Documentation
% n size of each dimension of our square cellular automata grid
% P_HIV fraction (probability) of cells initially infected by virus
% P_i probability of a healthy cell becoming infected if its
% neighborhood contains 1 I1 cell or X I2 cells
% P_v probability of a healthy cell becoming infected by coming
% in contact with a virus randomly (not from its
% neighborhood)
% P_rep Probability of a dead cell becoming replaced by a healthy
% cell
% P_repI Probability of a dead cell becoming replaced by an infected
% cell
% X Number of I2 cells in the neighborhood of an H cell that
% can cause it to become infected
% tau1 tau1 is the number of timesteps it takes for an acute
% infected cell to become latent.
% tau2 tau2 is the number of timesteps it takes for a latent
% infected cell to become dead.
% totalsteps totalsteps is the total number of steps of the CA (the
% total number of weeks of simulations)
% grid our cellular automata (CA) grid
% tempgrid tempgrid is a temporary grid full of random numbers that is
% used to randomly add different states to our CA grid.
% taugrid taugrid is a grid the same size as our CA grid that stores
% the number of timesteps that a cell has been in state I_1.
% If the number reaches tau1, then the state changes to I_2.
% state state is a [5 x totalsteps] size matrix that stores
% the total number of cells in each state at each timestep
% and the last row stores sum of I_1 and I_2 at each timestep
% timestep each simulation step of the cellular automata
% 1 timestep = 1 week of time in the real world
% nextgrid nextgrid is a temporary grid. It is a copy of the CA grid
% from the previous simulation. It stores all the CA rule
% updates of the current timestep and stores it all back to
% the grid to display.
%% Clean-up
clc; % clears command window
clear all; % clears workspace and deletes all variables
close all; % closes all open figures
%% Parameters
n = 100; % meaning that our grid will have the dimensions n x n
P_HIV = 0.05; % initial grid will have P_hiv acute infected cells
P_i = 0.997; % probability of infection by neighbors
P_v = 0.00001; % probability of infection by random viral contact
P_rep = 0.99; % probability of dead cell being replaced by healthy
P_repI = 0.00001; % probability of dead cell being replaced by infected
X = 4; % there must be at least X I_2 neighbors to infect cell
tau1 = 4; % time delay for I_1 cell to become I_2 cell
tau2 = 1; % time delay for I_2 cell to become D cell
totalsteps = 600 ; % total number of weeks of simulation to be performed
savesteps = [3 7 11 15 20 25 50 100 150 200 250 300 350 400 450 500];
%timesteps for which we want to save simulation image
%% States
% State 1: H: Healthy (Color- Green)
% State 4: I_1: Active Infected (Color- Cyan)
% State 3: I_2: Latent Infected (Color- Blue)
% State 2: D: Dead (Color- Black)
%% Initial Grid
else
nextgrid(x,y)=1;
end
end
end
end
% to assign the updates of this timestep in nextgrid back to our grid
grid=nextgrid;
% to display the grid at the end of each timestep
print1(grid);
% to save the image of the simulation every 25 timesteps as a pdf
if(find(savesteps==timestep))
saveas(gcf,strcat('Model1Timestep',num2str(timestep),'.pdf'));
end
state(1,timestep) = sum(sum(grid(2:n-1,2:n-1)==1));
state(2,timestep) = sum(sum(grid(2:n-1,2:n-1)==2));
state(3,timestep) = sum(sum(grid(2:n-1,2:n-1)==3));
state(4,timestep) = sum(sum(grid(2:n-1,2:n-1)==4));
timestep=timestep+1; % to move to the next timestep
end
% The following lines of code are to display a graph of each state of
% cells during simulation
set(figure, 'OuterPosition', [200 100 700 500]) % sets figure window size
plot( 1:totalsteps , state(1,:), 'g', ...
1:totalsteps , state(4,:), 'c', ...
1:totalsteps , state(3,:), 'b', ...
1:totalsteps , state(2,:), 'k' , 'linewidth', 2 );
legend( 'Healthy', 'Acute Infected', 'Latent Infected', 'Dead', ...
'Location' ,'NorthEast' );
saveas(gcf,strcat('Model1GraphSingleRun.pdf'));
3 仿真结果
4 参考文献
[1]李眩, 童百利, and 吴晓兵. "基于元胞自动机的传染病传播和控制仿真模型." 辽宁工业大学学报:自然科学版 40.5(2020):6.
部分理论引用网络文献,若有侵权联系博主删除。