ABSTRACT | PRESENTATION | POSTER | RESEARCH PAPER | FOREST FIRE

FIRE SPREAD MODEL

Introduction

This model was developed with a simulation engine for fire spread model. This simulator can be used to simulate any two dimensional cell space models.

To begin you have to understand the how this simulation works, you first have to consider an n-by-n matrix or a two dimensional square of numbers. Each cell in the matrix represents a specific location for the fire to spread. To further illustrate the content of each cell space in the matrix you have to consider these phases, and fuel which is will also help determine what happen to the cell.
.
PHASES
0 – means the cell is unburning
1 – means the cell is currently burning
2 – means the cell is all burnt out

n-by-n matrix

         
         
         
         
         


The Simulator Algorithm


if (phase = burning && fuel > 1)
then fuel = fuel -1

else if (phase = burning && fuel = 1)
then phase = burnt and fuel = 0

else if (phase = burnt)
{
   do nothing
}
else if (phase = unburning && atleast 2 inputs are burning && fuel >= 1)
{
   phase = burning
}
else, do nothing

The phases and the fuel levels will be loaded in the initial state from an input file.

This model needs four inputs for the four neighbors (north, south, east and west), set of state (which include the three phases and the fuel level), and output function, a state transition function (where the simulator algorithm will be placed), run function (which will go through each cell) and a garbage collector that will clean up the buffer.


Now that the basics are established lets now move on to more details. After you’ve drawn out your design you then have to think about a few things. Lets look at some of the code.

/*
Prevent this header from being included twice in the same file.
*/
#ifndef __sim_package_h_
#define __sim_package_h_

/*
This is the header file and simulator implementation for a cell space
modeling and simulation package.*/

/*
This is an Abstract model class. All cell models should be derived from this model and implement its pure virtual functions.
*/
class model
{
    public:
/*
Constructor.
*/
model()
{
}
/*
Virtual destructor.
*/
virtual ~model()
{
}
/*
Pure virtual state transition function.
*/
virtual void state_transition_func(const void* x) = 0;
/*
Pure virtual output function.
*/
virtual void* output_func() const = 0;
/*
Pure virtual garbage collection function. Will be called
at the very end of every simulation cycle.
*/
virtual void gc_output(void* garbage) = 0;
};

This simulator class is specialized with a template argument that tells it what kind of model to simulator.

template <class mclass> class simulator
{
public:
/*
Construct an array of row by col cells. Each cell
has an instance of the template model.
*/
simulator(int rows, int cols)
{
this->rows = rows;
this->cols = cols;
/*
Create a rows x cols array of mclass objects.
*/
bush = new mclass*[rows];
output_values = new int*[rows];
for (int i = 0; i < rows; i++)
{

/*for every row create a column */
output_values[i] = new int[cols];
bush[i] = new mclass[cols];

}
}
/*
Destroys the cellspace and all of the models in it.
*/
simulator::~simulator()
{
for (int i = 0; i < rows; i++)
{
delete [] bush[i];
}
delete [] bush;
}

To run the simulation we define a function call run, that will run for each time step.

Algorithm of run function

for each time step
compute and print output at each cell

you then have to store the output of each cell in a temp array for it to be used compute the next state at each cell

for each outputted cell assign the values to input from temp array

end time step

This figure indicates the matrix and its four input neighbors

 

/*
Simulate the model for tend time steps.
*/
void run(int tend)
{
// for each time step
for (int i = 0; i < tend; i++)
{
// compute and print output at each cell
for (int y = 0; y < cols; y++)
{
for ( int x = 0; x < rows; x++)
{
output_values[x][y] = *((int*)(bush[x][y].output_func()));
cout << output_values[x][y];
}
cout << endl;
}
cout << endl;
// compute next state at each cell
for (int x = 1; x < rows-1; x++)
{
for (int y =1; y < cols-1; y++)
{
// Assign values to input from output array
input[0] = output_values[x+1][y];
input[1] = output_values[x-1][y];
input[2] = output_values[x][y+1];
input[3] = output_values[x][y-1];
// compute next states using input bush[x][y].state_transition_func(input);
}
}
// end of timestep
}

}

In the main you have to create a class that will take as argument the abstract model class and include such functions state transition function, the output function, and the garbage collection output function. In the main you would want to create an instance of the simulator class, and with the instantiated object you have to call the function run.

Consider my code for my state transition function. It will take in the four neighboring inputs from the simulator class. Also to check the condition for at-least two burning inputs you have to create a counter that will count the amount of inputs that are burning.

void state_transition_func(const void* x)
{
const int *burning_input = (const int*)x;
int burning_counter = 0;
for( int counter = 0; counter < 4; counter++)
{
if (burning_input[counter] == 1)
{
burning_counter++;
}
}
// count number of values in burning_input that are burning
if ((phase == 1) && (fuel > 1))
{
fuel -= 1;
}
else if ((phase == 1) &&(fuel == 1))
{
phase = 2;
fuel = 0;
}
else if (phase == 2)
{
//do nothing
}
else if(((phase == 0) && ((burning_counter > 1 )) && (fuel >=1)))
{
phase = 1;
}
}


home | about me | research | mentor | images | links