The Fire model is a simple model that simulates the spread of a fire through a forest. The forest is represented as a grid of cells, which may be empty. In terms of agent-based modelling, the
Agent
represents each tree in the forest, and the state of the agent is one of three possibilities: BURNABLE
, BURNING
, or BURNT
.
Model
represents the forest itself, and the model is initialized with a certain density of trees. At each step of the simulation, the fire can spread from a burning tree to neighbouring trees.
For background on this model see the paper https://www.researchgate.net/publication/256662471_A_Cellular_Automata_Mo del_for_Fire_Spreading_Prediction
This implementation is very similar to Game of Life, with the following differences:
Model
grid is finite with boundaries (so torus=False
).Cell
.
In the Fire model, only some grid locations contain an agent, Tree
. Tree
agent has a state that can be BURNABLE
, BURNING
, or BURNT
.Model.step
should perform simultaneous update (similar to Game of Life).Agent
/ Tree
and Model
/ Forest
Agent
/ Tree
classstate
which is BURNABLE
, BURNING
, or BURNT
.get_neighbors
to return a list of all neighbours.compute_step
to compute the update, to state
, needed in the next step.step
to apply the update (that was computed in compute_step
).1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Model
/ Forest
classThe Model
/ Forest
class stores the model parameters,
the model geometry (space/grid),
and the agents in the model.
The basic structure of this class is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Agent
/ Tree
classModel
/ Forest
classThe Model
/ Forest
class has parameters width
, height
, density
, pr_spread
, and pr_burnout
.
width
and height
are stored in grid
so do not need to store them explicitly. density
is only used in __init__
method, when adding agents, so we do not need to store that also.pr_spread
and pr_burnout
and needed during the simulation so are stored using 1 |
|
The model space is a SingleGrid
with non-toroidal boundary conditions, i.e., torus=False
.
Create the agents/trees by iterating over the grid locations and create an agent (with probability density
). An agent/tree has default state of BURNABLE
We will add stuff here later, when we add data collection facilities.
The mesa library has a DataCollector
class that can be used to collect data during the simulation. We will add a data collector to collect the number agents in each state at each step. This will allow us to plot progression of the fire over time.
running
flag to Model
classIn Model.__init__
, in "# init simulation" section we set running
flag to True
, to indicate that the simulation is still running. This flag will be set to False
when there are no agents/trees with state BURNING
.
In Model.step
we wrap the existing update code by first checking to see if the model is still running, if not we return immediately. And after the existing update code we check if the simulation has ended (i.e. there are no more BURNABLE
trees):
1 2 3 4 5 6 7 8 |
|
To use the DataCollector
class, we create an instance of it in the Model.__init__
method. Where we list the information we want to collect.