## Introduction

There are some events in any area which have specific behavior in spreading, such as fire, infection virus or computer virus. There are common patterns in all of mentioned examples for instance, they are complex in prediction next part, and need huge mathematic calculation in order to anticipate next point of spreading. I have focused on fire spreading in this article.

Fire occurs so many damages in every aspect of life, human injuries and economic matters which we cannot neglect its hurts. It becomes worse when it spreads widely. Therefore, predicting fire spread is important. Obviously having comprehensive knowledge about avoiding fire in new position can prevent from its consequences. In fact, when flames reach to potential fuels, combustion will happen and fire will move in new position.

There are some different factors which are playing important role in fire spread such as fuel type and load, wind velocity, humidity and slop, we can draw a pattern from fire behavior and approximate next point in order to stifle fire in new point. There are limited tools in some areas such as ship and we do not have complete and professional firefighting team.

Using Markov Chain Monte Carlo for fire simulation is a fast and proper solution because it is memoryless while mathematic formula with less information about next point is time consuming. In this approach there is a function to generate random number between zero and one and it is the probability of flame spread, if the probability of ship room which has been calculated from influence of fire is greater than this number, so fire will go advanced, otherwise fire will die out.

## Modeling and simulation

Modelling and simulation of any phenomena needs to analyze which involves parameters and their relations. These parameters can be considered as system components and by using mathematical equations with random events, we can build a concrete and accurate model which can visualize system behavior (fire spread) and show the best result for predicting next action. In general speaking, we can combine all of criteria and then illustrate result from these set of conditions.

Simulation methods has revolutionized in engineering science. We should make abstraction of reality by modelling and implement modelling over time by simulation. When time elapsed we must observe that whether simulation has implemented modelling in a best quality or not. It is nearly dependent on good understanding of concepts, assumptions and constraints from desired subject.

## Simulation Steps

1. Gain involved parameters

2. Build environment in virtual world

3. Change and control parameters with implemented tools such as sliders which can be

assigned different values between an interval or button with on and off options

4. Show virtual environment according specific values for parameters and start operations, in

simple words it should be like an animation which some actors have given hand in hand to

play their role and effect on the whole story by their properties and characters and show us

a fact on give messages for conclusion.

## Why Simulation

1. Cheap: Obviously testing different situation in real world is very expensive, for an instance

simulation of earthquake or hurricane.

2. Safe: Simulation of natural catastrophe, as I mentioned above, have great danger and will

destroy environment.

3. Faster than real time: With the aid of “if then else”, we are able to analysis different values

for different parameters, as soon as changing them with some tools such as sliders or buttons and program environment will change according to them and it does not take long time.

4. More realistic than traditional experiments: We can set parameters in optional value and

acquire more accurate results.

5. Configuration of environment parameters are easy.

6. Test as much as it needs: It is possible to test so many times without any stress of expense

and any destruction.

7. Train it in visual manner: After building simulation, it is very useful for training to someone

who are involved or related to the subject of simulation i.e. firefighting or rescue forces.

## Simulation of Random Events

Fire spread is a random event and it has not precise mathematical treatment or if there are some

equations according Rothermal equations, we have to spend abundance time and money for analyzing, therefore best approach is to approximate results and gather them on a table and compare and discuss about it.

## Markov Chain

Markov Chain is a mathematical system, it has countable states and transition occurs from one state to another state with the probability P. The most fundamental Markov chain property is memorylessness. In simple words, this random process is without memory; it means that next state is just dependent to current state, not past events; also it is called Markov property. Markov is very useful and applicable for modelling real world.

In a better word, Markov Chain is discrete random process during time with Markov property which is located in specific state in each stage; stages are often in same discrete time interval. System is changing randomly; therefore, it is impossible to predict Markov Chain state in specific point in future, although some statistical property is predictable. Shifting between state is called transition and the probability of this changing is called transition probability, these states and their transition`s probability is formed as Markov Chain.

Markov Chain converts statistical concepts to simple mathematical language. It is included sequence of random variables (X_{0, }X_{1}, X_{2}, …), each state is a random variable, as you can see in below figure there are three options for each state to transit to another location. For example, State 0 with the probability 25% will go to State 1 and with the probability 15% will go to State 2 and with the probability 60% stand to current position and will not move. All of these transition can gather to a matrix as it is illustrated on below picture right side, so we convert probability of transition between Markov Chain to a mathematical matrix.

## The Formal Definition

Conditional Probability of transitions:

The transition probability from state i^{th }to state j^{th }in * 1* motion:

The transition probability from state i^{th} to state j^{th} in * n* motions:

### Random Walk

One of the famous Markov Chain is ‘Random Walk’; the location will be changed in each step with the probability P. There are two possible transition, one is (+1) integer number and other one is (-1) integer number. Random Walk is to study about path which is included random and consecutive steps, for an instance travelled path by a molecule in a gas or liquid, gambler`s financial status and stock price fluctuation. These steps occur in discrete time and are indexed by natural numbers (X_{1, }X_{2, }….). In general speaking, Random Walk is fundamental subject in Markov process topic and has a close relation with propagation model such as fire spread.

Random Walk might happen in a graph, direct linear or flat page. Image that on moving is on the flat and nets page, it starts from one node and then will go to another node with the specific probability P, eventually we can define series on

It will remain a touchy question, where is moving after n steps? Obviously we cannot calculate and determine moving`s random position, but we can discuss about its probability distribution as follow:

Expected Value:

Also by using of the fact that steps are independent from each other, we can infer that the average of changing of location for moving is a degree of

### Mont Carlo Method

Mont Carlo methods or Mont Carlo experiments are set of computational algorithms which are based on repeated random variables. It is applicable and suitable when we have no way to calculate exact result with deterministic algorithm. Therefore, it is very useful to simulate some natural disaster such as fluid and fire, because of these phenomena have significant uncertainly in input value. This name come from a famous casino in Mont Carlo where physics scientist`s uncle gambled there.

## Mont Carlo Pattern

- Define specific domain for inputs, in here, it is a range number between zero and one.
- Generate random numbers
- Specific calculation, in here, whether the random number is less than 0.8 or not?
- Merge results and go advance, in here, if the answer of above question is positive go to next state.

Markov Chain Mont Carlo which is included Mont Carlo Random Walk that is a set of algorithms for sampling from probability distributions which is based on Markov Chain. Chain starts from optional node and then the processes will repeat several times and often after a while will reach a constant distribution, the chain is desire if this time would be short as possible as it can. This approach is very useful for sometimes when we have complicated computational operations and it is very time-consuming or we have to spend much cost to achieve good and reasonable result.

## Requirements

The main requirement to simulate fire is to collect data from room environment in ship by sensors and do some computation with parameters which are involved in fire spread, and then I need a procedure to take and count time because fire simulation is a phenomenon which is changing over time.

This project needs to have these preconditions:

1. MS SQL Server 2008

2. Visual Studio 2008 version 9 (.net 3.5)

First run application and follow these steps:

- select one room from combobox.
- then change properties such as humidity, fuel or etc.
- Click on “Apply” button in order to save your new configuration value.
- Click on “Set Config” button in order to set your specific value for each four rooms.
- Click on “Sort” button in order to sort rooms and show arrows based on their priority to set fire.
- Finally; Click on “Start” to see simulation.

## Using the code

**Create Data Base**

USE [Fire] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tblFire]( [Room] [int] NULL, [FuelType] [int] NULL, [FuelLoad] [int] NULL, [Wind] [int] NULL, [Humidity] [int] NULL, [Slope] [int] NULL, [SolarAspect] [int] NULL, [Prob] [float] NULL ) ON [PRIMARY] GO

**Calculate Average intensity and make the probability of each room**

Dim intAve As Double intSum = ((10 - CInt(Me.Humidity.Value)) + CInt(Me.FuelType.Value) + CInt(Me.FuelLoad.Value) + CInt(Me.WindVelocity.Value) + CInt(Me.Slope.Value) + CInt(Me.Temperature.Value)) intAve = intSum / 6 intAve = intAve / 10 intAve = Math.Round(intAve, 1)

**Set Fire (Go to Next State)**

Private Sub SetFire4_1() If token4 = 1 Then Me.btnFire4_1.Visible = True End If End Sub

**Stifle Fire (Come Back to Previous State)**

Private Sub StifleFire4_1() If token4 = -1 Or token4 = 0 Then Me.btnFire4_1.Visible = False End If End Sub

**Apply Changing Setting**

Try Slope SolarAspect Prob where Room=" + Me.comboRoom.SelectedText.ToString() strsql = "update tblFire set FuelType=" + Me.FuelType.Value.ToString() & _ ", FuelLoad= " + Me.FuelLoad.Value.ToString() & _ ", Wind= " + Me.WindVelocity.Value.ToString() & _ ", Humidity= " + Me.Humidity.Value.ToString() & _ ", Slope= " + Me.Slope.Value.ToString() & _ ", SolarAspect= " + Me.Temperature.Value.ToString() & _ ", Prob= " + intAve.ToString() & _ " where Room=" + Me.comboRoom.Text Dim objcommand As New SqlCommand(strsql, cn) cn.Open() objcommand.ExecuteNonQuery() Catch ex As Exception Finally cn.Close() End Try

**Fetch Data to Set Config**

Try Slope SolarAspect Prob where Room=" + Me.comboRoom.SelectedText.ToString() strsql = "update tblFire set FuelType=" + Me.FuelType.Value.ToString() & _ ", FuelLoad= " + Me.FuelLoad.Value.ToString() & _ ", Wind= " + Me.WindVelocity.Value.ToString() & _ ", Humidity= " + Me.Humidity.Value.ToString() & _ ", Slope= " + Me.Slope.Value.ToString() & _ ", SolarAspect= " + Me.Temperature.Value.ToString() & _ ", Prob= " + intAve.ToString() & _ " where Room=" + Me.comboRoom.Text Dim objcommand As New SqlCommand(strsql, cn) cn.Open() objcommand.ExecuteNonQuery() Catch ex As Exception Finally cn.Close() End Try

**Start Set Fire Over Time**

If Me.sortlistbox.Items(3).ToString() = Me.btnProb1.Text Then AddHandler Count1.Tick, AddressOf Count_Tick1 Me.a.Text = "1" ElseIf Me.sortlistbox.Items(3).ToString() = Me.btnProb2.Text Then AddHandler Count1.Tick, AddressOf Count_Tick2 Me.a.Text = "2" ElseIf Me.sortlistbox.Items(3).ToString() = Me.btnProb3.Text Then AddHandler Count1.Tick, AddressOf Count_Tick3 Me.a.Text = "3" ElseIf Me.sortlistbox.Items(3).ToString() = Me.btnProb4.Text Then AddHandler Count1.Tick, AddressOf Count_Tick4 Me.a.Text = "4" End If

**Fire Spread**

**If the whole of room fires so go to the next room with high probability**

Private Sub Count_Tick1(ByVal sender As System.Object, ByVal e As System.EventArgs) Cisco\Desktop\fire\Timer\time\time\fire" Me.btnProb_1.Visible = True Me.btnTime_1.Visible = True Me.p1.Visible = True Me.t1.Visible = True Dim bytes1(99) As Byte Dim rnd1 As New Random() Dim num As Double num = rnd1.NextDouble 'get the time Me.Text = sender.Days & " days, " & sender.Hours & " hours, " & sender.Minutes & " minutes and " & sender.Seconds & " seconds left." 'Count Up Dim iMin As Integer iMin = (CInt(sender.Minutes)) * 60 iMin = iMin + sender.Seconds Me.btnTime_1.Text = 239 - iMin If token 4 Then token = 4 End If Me.btnProb_1.Text = num If num < Me.btnProb1.Text Then token = token + 1 SetFire1_1() SetFire1_2() SetFire1_3() SetFire1_4() Else token = token - 1 StifleFire1_1() StifleFire1_2() StifleFire1_3() StifleFire1_4() End If If Me.btnFire1_4.Visible = True And Me.dd.Text = "NO" Then Me.dd.Text = "YES" 'Declares a variable for our countdown timer. Dim Count1 As CountDown 'Set the time to 3 minutes, this can be done in two ways '----way ---- Count1 = New CountDown(0, 4) '-------- 'starts the timer Count1.Start() If Me.a.Text = "1" Then If Me.b.Text = "4" Then AddHandler Count1.Tick, AddressOf Count_Tick4 ElseIf Me.b.Text = "3" Then AddHandler Count1.Tick, AddressOf Count_Tick3 ElseIf Me.b.Text = "2" Then AddHandler Count1.Tick, AddressOf Count_Tick2 End If End If If Me.b.Text = "1" Then If Me.c.Text = "4" Then AddHandler Count1.Tick, AddressOf Count_Tick4 ElseIf Me.c.Text = "3" Then AddHandler Count1.Tick, AddressOf Count_Tick3 ElseIf Me.c.Text = "2" Then AddHandler Count1.Tick, AddressOf Count_Tick2 End If End If If Me.c.Text = "1" Then If Me.d.Text = "4" Then AddHandler Count1.Tick, AddressOf Count_Tick4 ElseIf Me.d.Text = "3" Then AddHandler Count1.Tick, AddressOf Count_Tick3 ElseIf Me.d.Text = "2" Then AddHandler Count1.Tick, AddressOf Count_Tick2 End If End If If Me.d.Text = "1" Then Me.PictureBox1.BackgroundImage = Image.FromFile(path & "\Fire.jpg") End If End If End Sub