MIME-Version: 1.0 Content-Location: file:///C:/2D3AA084/firespread.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" FIRE SPREAD MODEL

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 ce= ll 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 squ= are of numbers. Each cell in the matrix represents a specific location for the fir= e 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 dete= rmine what happen to the cell.

.

PHASES

0 – mea= ns the cell is unburning

1 – mea= ns the cell is currently burning

2 – means the cell is all burnt out

 

n-by-n matrix

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 =

 

The Simulator Algorithm

 =

if phase is equal to burnin= g and fuel is greater than 1

then fuel is assigned fuel = minus one.

 

   &nbs= p;        else if phase is equal to burning and fuel is equal to= one

   &nbs= p;        then phase is assigned burnt and fuel is assigned 0

 

else if phase is equal to b= urnt, do nothing

 

   &nbs= p;        else if phase is equal to unburni= ng and at-least 2 inputs are burning and fuel is greater than equal to one, th= en phase is assigned burning.

 

 

if (phase =3D burning &= & fuel > 1)

then fuel =3D fuel -1

 

else if (phase =3D burning = && fuel =3D 1)

then phase =3D burnt and fu= el =3D 0

 

else if (phase =3D burnt)

{

do nothing

}

else if (phase =3D unburning && atleast 2 inputs are burning && fuel >=3D 1)

{

phase =3D burning

}

else, do nothing

 

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

 

This model needs four inputs for the four neighbors (n= orth, 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 ea= ch cell) and a garbage collector that will clean up the buffer.  

 

 

Now that the basics are established lets now move on t= o more details.  After you’ve d= rawn 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 fi= le.

*/

#ifndef __s= im_package_h_

#define __sim_package_h_

 

/*

This is the header file and simulator implementation for a c= ell 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.<= /p>

*/

class model

{

    &nbs= p; public:

    &nbs= p;       /*

    &nbs= p;       Constructor.

    &nbs= p;       */

    &nbs= p;       model()

    &nbs= p;       {

    &nbs= p;       }

    &nbs= p;       /*

    &nbs= p;       Virtual destructor.

    &nbs= p;       */

    &nbs= p;       virtual ~model()

    &nbs= p;       {

    &nbs= p;       }

    &nbs= p;       /*

    &nbs= p;       Pure virtual state transition function.

    &nbs= p;       */

    &nbs= p;       virtual void state_transition_fun= c(const void* x) =3D 0;

    &nbs= p;       /*

    &nbs= p;       Pure virtual output function.

    &nbs= p;       */

    &nbs= p;       virtual void* output_func(= ) const =3D 0;

    &nbs= p;       /*

    &nbs= p;       Pure virtual garbage collection function.  Will be called

    &nbs= p;       at the very end of every simulation cycle.<= /span>

    &nbs= p;       */

    &nbs= p;       virtual void gc_output(voi= d* garbage) =3D 0;

};

 

 

 

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

 

te= mplate <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 =3D rows;

            =       this->cols =3D cols;

            =       /*

            =       Create a rows x cols array of mclass objects.

            =       */

            =       bush =3D new mclass*[rows]= ;

            =       output_values =3D new int= *[rows];

            =       for (int i =3D 0; i < rows; i++)

            =       {        &= nbsp; 

 

            =       /*for every row create a column */

        =               =   output_values[i] =3D new = int[cols];

            =             <= span class=3DGramE>bush[i] =3D new mclass[cols];

 

            =       }

            }

            /*

            Destroys the cellspace and all of= the models in it.

            */

            simulator::~simulator()

            {

            =       for (int i =3D 0; i < rows; i++)

            =       {

            =             <= span class=3DGramE>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

 =

fo= r each time step

co= mpute and print output at e= ach cell

 

yo= u then have to store the output of each cell in a temp array for it to be used compute the next stat= e at each cell

 

fo= r each outputted cell a= ssign the values to input from temp array

 

en= d time step =

 

This figure indicates = the matrix and its four input neighbors

 

 

 

N

(x-1,y)

 

 

W

(x-1,y)

 

 

 

E<= /p>

(x,y+1)

 

 

S

(x+1,y)

 

 

/*

Simulate the model for= tend time steps.

*/

vo= id run(int tend)

{

// for each time step<= o:p>

fo= r (int i =3D 0; i < ten= d; i++)

{

// compute and print o= utput at each cell

      for (int y =3D 0; y < cols; y++)

      {

            for ( int x =3D 0; x < = rows; x++)

            {

output_values[x][y] =3D        *((int*)(bush[x][y].output_func()));

            =             &nb= sp;     cout << output_values[x][y];

            }

            =       cout << endl;

      }

            =       cout << endl;

// compute next state = at each cell

      for (int x =3D 1; x < rows-1; x++)

      {

            for (int y =3D1; y < co= ls-1; y++)

            {

// Assign values to in= put from output array

      input[0= ] =3D output_values[x+1][y];

      input[1= ] =3D output_values[x-1][y];

      input[2= ] =3D output_values[x][y+1];

      input[3= ] =3D output_values[x][y-1];

// compute next states= using input bush[x][y].state_tran= sition_func(input);  

       }

}

            =       // end of timestep  

} 

 

}

 

In the main you have to create a class that will take as argument the abstract model class and incl= ude such functions state transition function, the output function, and the garb= age collection output function. In the main you would want to create an instanc= e 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.

 

vo= id = state_transition_func(const void* x)

{

            const int *burning_input =3D (const int*)x;

            int b= urning_counter =3D 0;

            for( int counter =3D 0; co= unter < 4; counter++)

            {   

            =       if (burning_input[counter]= =3D=3D 1)

            =       {

            =             <= span class=3DSpellE>burning_counter++;

            =       }

            }             =                

        =    // count number of values in burning_input that are burning

            =       if ((phase =3D=3D 1) && (fuel > 1))

            =       {

            =             <= span class=3DGramE>fuel -=3D 1;

            =       }

            =       else if ((phase =3D=3D 1) &&(fuel =3D=3D 1))

            =       {

            =             <= span class=3DGramE>phase =3D 2;

            =             <= span class=3DGramE>fuel =3D 0;

            =       }

            =       else if (phase =3D=3D 2)

            =       {

            =             /= /do nothing

            =       }

else if(((phase =3D=3D 0) && ((burning_counter > 1 )) &&   &nbs= p; (fuel >=3D1)))

        =           {

        =                = phase =3D 1;

        =           }

            }