banner-nll

Lab 4 Continued...

An important concept in cellular automata is the concept of neighbors.  The cells situated touching a particular cell are its neighbors.  In net logo, the four  neighbors touching the sides of the cell are referred to neighbors4.  There are actually eight cells that touch the cell in the middle, the four on the sides and four more that touch on the corners.  These eight neighbors are called neighbors Lets look at neighbors4 first. In the command center, enter the  following:

    O>   ask patch 0 0 [set pcolor green]

    O> crt 1

    T> set color green

    T> ask neighbors4 [set pcolor red]

Your screen should look like this.


The red  squares represent the four neighbors sharing sides with the one we created the  turtle on.

The  black squares are the cells added to the four neighbors to give us eight  included in the neighbors command.

Right  click on each of the squares and inspect each patch.  Note the coordinates for  each patch.  Think of how movement can occur by changing the x coordinate  positively or negatively.  How will movement occur if we change the y coordinate  positively - negatively?

Continued motion in one direction will require what type of changes to the x or  y coordinates?  We refer to the coordinates for the patches as pxcor and pycor.

 

Now we will explore a program written with only patches and no turtles.  We know that patches do not move but in this simulation, the “fire” seems to move.

Download and open this fire model from the Netlogo 1.3 Model’s Library. Set up and run the program several times.  Adjust the slider of the density of the forest.  What effect does the density have regarding the survival of the forest after the fire?

This program has no turtles.  Study the code and identify the parts that set up the density of the forest.  “Make some green trees” indicates how this is done.  Notice that the density is a global set by the slider so it does not appear in the globals list.

The  blue border is used to prevent wrapping.  Does it need to be on only three sides?

Would  it function on two sides?

You may  notice that the red color fades to black as the fire progresses.  Where does this occur in the code?

We are going to redo some of this code so that our fire could start anywhere in the forest and will spread in relation to the wind direction we set after the forest is set up.  

First  cut from the code the section that sets up the red line on the left.  Now write in code to set fire to just one patch at random.  The command is:

    ask random-one-of patches [set pcolor red
               set burned? true]

 Since you want this to occur only once in the setup, you need to move it to the last step of setup. This may create problems with the brackets surrounding the IF statements above.  Be sure to count the opening and closing brackets after the first “ask patches”. Now when you click setup the screen should look like this,  with the red patch anywhere on the screen.

Continue this lab

 


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.