NETLOGO TUTORIAL III · NETLOGO TUTORIAL III Lisa McManus NBHS STEM Club. GOOGLE DOCS We will write...
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/1.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/6.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/7.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/8.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/10.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/12.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/13.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/14.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/15.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/16.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022062605/5fd84bcec5316f0dd610d3ba/html5/thumbnails/17.jpg)
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