NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write...

17
NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club

Transcript of NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write...

Page 1: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

NETLOGO TUTORIAL IIILisa McManusNBHS STEM Club

Page 2: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

GOOGLE DOCS

We will write all of our code in a Google doc

We can then copy and paste this code into the ‘NetLogo Code’ section

Remember to click ‘Recompile Code’ after you make your changes!

Page 3: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

PROCEDURES

A set of instructions is known as a procedure or a function

Today we will write all of the procedures for our coral-algae model in a Google Doc

Page 4: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

CORAL-ALGAE MODEL: VERSION 1.0

Page 5: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

to setup-algaeask n-of 10 patches [set pcolor green]

end

to grow-algaeask patches with [pcolor = green]

[ ask neighbors [if pcolor = black [set pcolor green] ]end

Go back to the Command Center in the observer view

Enter setup-algae in the Command Center

Enter grow-algae …. Try entering grow-algae several times

Page 6: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

ALGAE GROWTH

Page 7: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Go back to the ‘NetLogo Code’ tab

Type the following and then press ‘Recompile Code’

to setup-coralask n-of 10 patches [set pcolor pink]

end

Let’s change our code so that algae and coral can only grow on ‘free space’, which we represent with our black patches

to grow-algaeask patches with [pcolor = green]

[ ask neighbors [if pcolor = black [set pcolor green] ]end

Page 8: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Let’s change our code so that algae and coral can only grow on ‘free space’, which we represent with our black patches

to grow-algaeask patches with [pcolor = green]

[ ask neighbors [if pcolor = black [set pcolor green] ]end

to grow-coralask patches with [pcolor = pink]

[ ask neighbors [if pcolor = black [set pcolor pink] ]end

Page 9: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Here are the setup and go procedures that call on our other procedures

to setupclear-allsetup-algaesetup-coralreset-ticks

end

to goif ticks >= 50 [ stop ]grow-coralgrow-algae

end

Page 10: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

REEF PLOT

Page 11: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

SLIDERS

In our model, we have the following sliders called time-steps, initial-algae and initial-coral

These are variables in our model

What do we need to change in the code in order to make these sliders ‘live’?

Page 12: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

ADDING REALISM

Algae grow faster than corals

Algae can also grow over corals, although not as fast as they can over free space

How can we modify our code to reflect this?

Page 13: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Free space

Coral Algae

coral mortalitygrowth

algal mortality through grazing

algal overgrowth onto coral

coral recruitment

Page 14: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Free space

Coral Algae

coral mortalitygrowth

algal mortality through grazing

algal overgrowth onto coral

coral recruitment

Page 15: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Let’s change our code so that at every time step, algae grows on free space with a probability of 40/100Note: ‘random’ is a NetLogo primitive that “rolls the dice” and gives you a value between 0 and the number you set

to grow-algae if random 100 < 40 [ ask patches with [pcolor = green] [ ask neighbors [if pcolor = black [set pcolor green] ] ] ] end

Page 16: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

How do we add a probability that algae will grow over coral?

Write a procedure called ‘grow-algae-coral’

Page 17: NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write all of our code in a Google doc We can then copy and paste this code into the ‘NetLogo

Let’s change our code so that at every time step, algae can grow on coral at a probability of 20/100

to grow-algae-coral if random-float 100 < 20 [ ask patches with [pcolor = green] [ ask neighbors [if pcolor = pink [set pcolor green] ] ] ] end