Lab 4 Random/Wiggle Walk

advertisement

CS108 Computer Science for All

Lab 4: NetLogo Experiments using

Random Walk and Wiggle Walk

Figure 1: Sample Interface for Diffusion Lab. The screen capture above shows the required layout of your program’s interface tab.

In this you will be creating a simple model of the movement of a contaminant through soil from the surface to the water table below the surface. The movement of a contaminant through soil is a very complex problem. Different types of contaminants move at different rates and react differently with different soils and other materials present. The amount of rainfall also affects how quickly contaminants move through soil. The model you will create will be greatly simplifies but it will allow us to run experiments and perform our firstsimulation. We will be evaluating the movement of contaminants in wet and dry soil.

Документ1 Page 1 of 10

In this lab, you will be writing a program that lets you experiment with two different types of turtle movement: the “random walk” and the “wiggle walk”.

These simple movements have useful behaviors and we will use them in more advanced models later in the semester.

There are two NetLogo video lectures this week:

1) NetLogo and the Random Walk – this can be used to simulate simple diffusion.

2)

NetLogo and the Wiggle Walk – this can be used to simulate more directional movement and is frequently used to simulate animal movement.

These videos explain the two types of walks and show how to create and use the slider on the Graphical User Interface to control the value of variables .

Resize Your World

NetLogo’s default World View settings show an area from -16 to

+16 on the x and y-axis. For this lab, you will need to change these settings.

 Go to the Interface tab and select the Settings Button (#1 to the right).

 The max-pxcor

and max-pycor must be 200 while min-pxcor

and min-pycor

must be -200 (#2 to the right).

 To keep this from making a world too large to fit on your display, set the

Patch size

to 1 pixel (#3 on right)

 We want the world to wrap only horizontally so turn off wrapping

Vertically (#4 on right).

#2

#3

#1

#4

Документ1 Page 2 of 10

Set Up Model

Here is what the world should look like when you press the setup button in your model. NetLogo clears the world. It creates agents and colors the patches as follows:

Agents

 You have 500 turtles that represent the contaminant.

 They are red, size 10 and have an initial heading of 180.

 They are all at the top of the world. To do this the following command must be included in the create turtles block

Patches

 Set the color of the patches to be brown

 Then color the bottom of the world blue to represent the aquifer. To do this the following command must be included in the ask patches block in the setup procedure

Where the Action is….

You will be running experiments using the model you create. In order to do that, you need to be able to alter the variables and measure the outcomes after those changes. Please set up the interface so that you can change the variables using sliders (as shown in figure 1 on the first page). The variables that need sliders are and the values needed are shown in the table below:

Slider diffLength

Minimum

Value

0.1 2

Maximum

Value

Increment

0.1 wiggleLeft wiggleRight

0

0

100

100

1

1

Документ1 Page 3 of 10

You will have two procedures that will be used to model the movement of contaminants through the soil.

1.

The go_random_dry procedure - This procedure uses the random walk you learned about in the NetLogo and the Random Walk video – this will be used to simulate simple diffusion of a contaminant through dry soils. Instead of using forward 1 you will be using forward diffLength.

2.

The go_wiggle_wet procedure - This procedure uses the wiggle walk you learned about in the NetLogo and the Wiggle Walk video – this will be used to simulate simple diffusion of a contaminant through wet soils (after it has rained). Instead of using forward 1 you will be using forward diffLength.

Also, the angles used in the left turn portion of the wiggle walk is wiggleLeft

( left wiggleLeft) and the right turn portion of the wiggle walk is wiggleRight

( right wiggleRight).

“Time” is Important

In order to be quantitative with our experiments, we need a way of counting the amount of “time” needed for the contaminants to reach the water table using the two different types of walks. For this, you will use NetLogo’s built-in tick feature.

As shown in the table below, you will need to put in the command rest-ticks at the end of the setup procedure and tick at the end of EACH go procedure. This does not actually measure time but the of iterations (cycles) through the procedure being run.

In the screen capture on the first page, the random walker took approximately

2212 ticks before it reached the blue water table. The number of ticks is approximate because as the walker neared the blue water table, I slowed the model speed and tried to click off the “RandomWalk” button when I believed the walker touched the boundary.

Документ1 Page 4 of 10

reset-ticks Call this at the end of setup.

Tick Advances the tick counter by one. Call this ONCE EACH TIME the walker takes a STEP in both “go_random_dry” and in

go_wiggle_wet”. It must be called OUTSIDE any ask turtle blocks, usually at the end of the procedure.

Running Your Experiments

Now comes the fun part – running experiments. Each of the different types of turtle movements, the Random walk and Wiggle Walk, involves randomness. The randomness of the process means that every time you run your model, your answer will be somewhat different. So when you run your experiments, you will need to repeat your experiment using the same input variables and average your results.

So for each experiment you will:

1) Set the sliders to the correct numbers for that experiment.

2) Click “setup”.

3) Click either “go_random_dry” or “go_wiggle_wet” depending on the experiment being run. Let the program continue and the turtles

(contaminants) move until one touches the blue water table. Stop the program manually before the walker hits the boundary.

4) Record the number of ticks it takes for your contaminants to reach blue water table on the experimental data sheet provided. You will either manually stop the program when the contaminant reaches the blue water or you can figure out how to have the procedure automatically stop when it reaches the blue water (patches)

5) Repeat the experiment (steps 2 -4 above) 10 times, recording the number of ticks in the data sheet each time.

6) Go to the next experiment and start.

Each student in the class will be assigned a contaminant to study: “Petroleum”,

“Pesticide”, “Benzene”, or “Bacteria”. Each contaminant has a different transport rate in the soil that is represented by its diffLength variable as show in the table below.

Документ1 Page 5 of 10

Values of diffLength for Each Contaminant

Contaminants

Petroleum

Pesticide

Benzene diffLength

0.2

1.3

2.0

Bacteria 0.7

After creating your program, you must perform 10 experiments for each of the 4 wetness setting given in the table below. The wetness level will affect what procedure you use and the values you use for the variables wiggleLeft and wiggleRight. Thus, you will perform a total of 40 experiments.

Wetness Levels for the Experiments Conducted

Wetness Level Procedure Used wiggleLeft Value wiggleRight Value

Dry go_random_dry NA NA

Moist

Wet

Saturate

go_wiggle_wet

go_wiggle_wet

go_wiggle_wet

100

70

45

100

70

45

Документ1 Page 6 of 10

Lab 4: NetLogo Experiments in Random Walk and Wiggle Walk

Grading Rubric (20 Points Total)

Done Points Task

2 A: Do the following:

1. Submit Three documents to your instructor:

A) NetLogo source code named: W4.

firstname .

lastname .nlogo.

B) Submit your completed Data Sheet for your simulation

C) A graph that shows your results for your contaminant and the results from 3 other students who used different contaminant types.

2. The first few lines of your code tap are comments including your name, the date, your school, and the assignment name (Lab 4: NetLogo

Experiments in the Random Walk and Wiggle Walk).

3

2

2

B: The code in the code tab of your program is appropriately documented with “inline comments.”

C. You include a description of you program in the Info section.

D: Your sliders are set up correctly as show below:

5

Slider Minimum

Value

Maximum

Value

Increment diffLength wiggleLeft wiggleRight

0.1

0

0

2

100

100

0.1

1

1

E: Program runs correctly:

 When “setup” is clicked, the NetLogo world is cleared, the world is colored brown, a blue water table appears at the bottom and 500 contaminant turtles appear at the top.

 When your go_random_dry procedure is clicked, your contaminants

(turtles) starts at the top and repeatedly takes one step of length diffLength per tick in a random ( any one of 360 degrees ).

 When your go_wiggle_wet procedure is clicked, your contaminants

(turtles) starts at the top and repeatedly takes one step per tick in a

Документ1 Page 7 of 10

4

2

5

5 wiggle walk - repeatedly making a turn to the left by a random number of degrees from 0 through the “wiggleLeft” slider specified degrees, makes a turn to the right by a random number of degrees from 0 through the “wiggleRight” slider specified degrees, then takes one step of length diffLength.

F: Data collected correctly. Your data sheet includes:

 The contaminant assigned to you and the results of each of the 40 experiments you ran.

 The average number of steps of the 10 experiments you ran for your contaminant at each wetness level (a total of 4 averages).

 The average number of steps calculated by students of the three types of contaminants different from your own. You do not need the number of ticks from each of their experiments, just the averages.

This is a total of 12 averages – 4 from each of 3 other students, if possible!

G: Create a graph of average number of ticks on the vertical (y) axis versus the wetness level on the horizontal (x) axis. Your graph must include the 16 averages reported in your Info section.

H: (Extra Credit) Program your walker (turtle) to stop automatically when it touches the blue patches.

I: (Extra Credit) Run the experiment for a different contaminant.

Collect the data for that contaminant on a different data sheet and create a different graph for your second owl.

Документ1 Page 8 of 10

Lab 4: NetLogo Experiments - Random Walk and Wiggle Walk

DATA SHEET

Name:

Date:

School:

Contaminant Type: diffLength

Left Turn Angle

Right Turn Angle

Dry

NA

NA

Saturated

4

5

6

Experiment No

1

2

3

7

8

9

10

Average (Mean)

Moist Wet

Number of Ticks

Other Students Average Data

Student Name/

Contaminant

NA – not applicable

Dry Moist Wet Saturated

Документ1 Page 9 of 10

Download