banner-nll

Lab 4 Continued..

When you run your program you will notice that the fire will burn in any direction.   In real life the fire is usually pushed in one direction by the prevailing  wind.  How can we simulate that with our model?

To do  this, we will need to define some global variables for the wind directions.

We will  also need to create some buttons so the user can set the wind direction after setup.  Go to the Interface page and create four buttons for the four main wind  directions.  The code should say set north true and so on for each direction. The titles of the buttons will just be the names of the winds. You will also need to add those four names to the globals list in the Procedures. 

Since  we will be using the pxcor and pycor of the random patch that will be on fire at the beginning of the simulation, we will also define a global for each of these  values.  Call them downwind in the pycor and crosswind in the pxcor.

Add  downwind and crosswind to the globals list at the top of the procedures.

Winds  are named for the direction from which they come.  Pycor will be affected by which types of winds?  If  pycor changes, which directions can the fire be going?

Pxcor will be changing if the fire is moving in what directions?

In the setup we want no wind determined so we set all wind variables at false.

Your code goes in just above the code you entered to set one patch on fire and looks  like this:

    set  north false
    set  south false
    set  east false
    set  west false 

That one patch that is burning will determine which others can burn so we have to start with its coordinates.  Once the one patch is on fire we will record its  location by setting the downwind and the crosswind from its pycor and pxcor.  It should look like this:

    ask random-one-of patches [set pcolor red
         set downwind pycor
         set crosswind pxcor
         set burned? true]

Locate the code in the procedure “to go”that indicates the trees are burning.  We need to change the  code so that the only trees or patches that burn are the ones standing downwind from the burning tree.  Our conditions are if one of its neighbors standing  upwind is burning then this tree will also burn.  If this tree lies upwind, it will not burn.  We must write IF statements for each of the four winds.  We  will also use combinatorial logic in the form of and conditionals.  So, a tree  or patch will burn only if it is green and one of its neighbors is burning and  if the wind is blowing so that it is situated downwind to that neighbor.   Can  you write that IF statement?

This is  what the code looks like now: 

    if any? neighbors4 with burned?

We will  change to neighbors instead of neighbors4 so the patch will look at all eight of  its neighbors.  If the wind is a north wind, which coordinate will be affected?

Will neighbors with higher or lower coordinate numbers be burned?  Your IF statement must first evaluate the global wind direction.  If the global is true  and if the coordinate of the burning tree or patch is the right number set from  the downwind, or crosswind variable set when the first patch or tree was set on fire then the tree will burn.  For example, if the wind is north; north will be true and the pycor will be the one affected.  The patches with smaller pycor number can be affected if they are neighbors of a burning tree. Write one set  for each of the four wind directions like this

    ask patches with [pcolor = green]
    [ if north = true and any? neighbors with  [burned?]
    and pycor < downwind [set pcolor red
    set burned-trees burned-trees + 1 ]]

Once that compiles, run it to see what the fire does.  After several runs, you see  that the fire spreads back to the original patch x or y coordinate.  This does  not look natural.  The wind would continue to push the fire downwind.  What  adjustment can we make so that the fire doesn’t burn back?  Could you advance the pxcor or pycor once the fire starts to spread?  If it is a north wind we  would want the pycor to get smaller at each iteration.  If it is a south wind we would want the pycor to get larger at each iteration.  We need a counter.

The  burning patches must look along only one coordinate to determine the direction  of burning.  Go to the code with burning?  and add a counter which will increase or decrease the pxcor or pycor at each iteration for each wind direction like this:

    ask  patches with [burning?]
        [  set burned? true
           set pcolor pcolor - 0.3 ]
           if north = true[set downwind downwind - 1]

Now that you have  finished this part of the tutorial, could you write code that would let the user set a combination wind like a northeast wind and have the fire burn in the right direction?


With Support from:

The NetLogo Learning Lab is part of modelingcomplexity.org, the home of the Mesa State College Center for Agent-Based Modeling.

This website is copyright by Mesa State College, 2004. All rights are reserved.

Some materials are adapted from the NetLogo User manual, and are copyright Wilensky, U. (1999). NetLogo.  Center for Connected Learning and Computer-Based Modeling. Northwestern University, Evanston, IL.