Fire Model

Background

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

For background on this model see the paper https://www.researchgate.net/publication/256662471_A_Cellular_Automata_Mo del_for_Fire_Spreading_Prediction

Implementation

This implementation is very similar to Game of Life, with the following differences:

Outline of core classes Agent / Tree and Model / Forest

Agent / Tree class

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Tree(mesa.Agent):


    def __init__(self, model):
        super().__init__(model)


    def get_neighbors(self): ...


    def compute_step(self): ...


    def step(self): ...

The Model / Forest class

The 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
class Forest(mesa.Model):


    def __init__(self, seed=None):
        super().__init__(seed=seed)

        # store model parameters

        # create the model space/grid

        # create agents in the model

        # setup data collector

        # init simulation


    def step(self):
        self.agents.do("compute_step")
        self.agents.do("step")

Implementing the Fire Model

Agent / Tree class

Model / Forest class

Store model parameters

The Model / Forest class has parameters width, height, density, pr_spread, and pr_burnout.

1
    self.pr_spread = pr_spread

Create the model space/grid

The model space is a SingleGrid with non-toroidal boundary conditions, i.e., torus=False.

Create agents in the model

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

Init simulation

We will add stuff here later, when we add data collection facilities.

Visualisation

Data Collector

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.

Adding running flag to Model class

1
2
3
4
5
6
7
8
    def step(self):
        if not self.running: return 

        self.agents.do("compute_step")
        self.agents.do("step")

        n_burning = self.count_state(Tree.BURNING)
        self.running = (n_burning>0)

Setting up the data collector

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.

Getting data from the data collector

Plotting the data

Batch Running