How much prior experience do you have with computer programming? For example, python, C, Java, Matlab or even HTML.
This is an introduction to NetLogo and agent-based modeling (ABM) for educators interested in learning ABM and how to use it pedagogically. The lessons starts with a short survey to assess prior experience with modeling and computer programming and then guides the learner through the basics of NetLogo and ABM.
This is an introduction to NetLogo programming and agent-based modeling. You will first answer a few questions about your prior experience with programming and modeling. Then you will learn the basics of NetLogo.
How much prior experience do you have with computer programming? For example, python, C, Java, Matlab or even HTML.
How much experience do you have creating agent-based models?
What are your expectations around learning NetLogo and agent-based modeling?
Which NetLogo platform are you using?
Note: The core functionality of NetLogo Web and NetLogo Desktop are the same, so it doesn't really matter for the purpose of this lesson, but it makes sense to learn on the platform you intend to use with students:
If your students have chromebooks, you will want to use NetLogo Web. (Everything will be here in the browser so just continue ahead)
If your students have laptops that can download desktop applications, you may want to use the desktop version because it is faster and has some features that haven't been added to the web version yet. You can download NetLogo Desktop here.
This page will introduce you to turtles, one of the most important things in NetLogo. Follow along with the steps below.
Notes if you are using NetLogo Web:
Creating and Moving Turtles
Click the Command Center and create a turtle by typing create-turtles 1. This created 1 turtle. Because this is something you do a lot in NetLogo, there is an abbreviation: crt. Try typing crt 50. That created 50 turtles.
The turtles are all facing random directions by default. What do you think it will look like if they all move forward the same distance? Type your answer below and then we'll try it in the next question.
Note: if you are using NetLogo Web, the Command Center is the first horizontal purple bar. If you are using NetLogo Desktop it is at the bottom of the interface.
Moving Turtles
Now let's ask the turtles to move. In the Command Center, type ask turtles [forward 10]. There is an abbreviation for this one too. You can just type ask turtles [fd 10], and it will do the same thing. To clear everything away, type clear-all, or ca for short (not every command has an abbreviation, but a lot of the most common ones do).
What does it look like when you create a bunch of turtles and ask them to all move forward the same distance? Why is this?
What do you think it will look like if you create a bunch of turtles and then have them each move forward a random distance instead of the same distance?
The command random number will produce a random integer greater than 0 and less than number. So random 10 will output a random integer greater than 0 and less than 10. The command random-float number does the same thing, except the output will be a decimal number instead of an integer.
Try creating a bunch of turtles and asking them to move forward a random distance. What does it look like? Does it look different if you use random vs random-float? Does it look different as you add more turtles? Try to explain why you see what you do for each question.
Emergence
The patterns you saw in the previous questions are a simple example of "emergent phenomena." You never told the turtles to make the shape they did. Each turtle just followed a simple command of moving forward, but a macro-level pattern emerged from all the individual actions. We will see many more examples of emergent phenomena. Can you think of an example of an emergent phenomenon? What about something that isn't an emergent phenomenon?
Moving individual turtles and turning
Using just the commands you've learned, how might you make a turtle move in a circle?
If you had any issues on this page, describe them below. If not, type something like "no problems" and continue on.
This page will introduce you to procedures, one of the most important ideas in NetLogo and programming in general. Follow along with the steps below.
Creating Procedures
If you had to type every command each time you wanted it to run, it would take forever to run computer programs. Instead, we can put a bunch of commands together into a procedure. Open up the NetLogo Code tab and we'll go through the steps of writing a procedure.
Copy and paste your move procedure below.
Buttons
To make things even easier, we can create a button to call a procedure.
Now you can click the button to call the procedure.
The Setup Procedure
As a convention, almost every NetLogo model has a procedure called setup with an accompanying button. This procedure is to set up the "world" of the model.
Each time you click the setup button, all the existing turtles should be cleared and new ones created.
Copy and paste your setup procedure below.
The Go Procedure
As a convention, almost every NetLogo model also has a go procedure and an accompanying button. This is generally the procedure used to make a model run continuously. It makes sense to have a unit of time in a model when it runs continuously. In NetLogo this unit is called a tick.
When you click the go button, it should now call the go procedure repeatedly. Each time the go procedure is executed, the ticks increase by 1, because you called the tick command inside the go procedure.
What behavior do you see? Were you surprised by it? Why is this behavior occurring? Answer in the box below.
Predicting effects of small changes
What do you think will happen if you change the code of your move-turtles procedure so that the turtles move forward a little bit more each tick? Write your prediction below.
Integrative Understanding
Change your move-turtles procedure so that turtles move forward slightly more each tick (something like 0.22). What pattern emerges? (You can use the Model Speed slider at the top of the model to make the model run faster or slower).
Most people do not predict the resulting pattern. Some predict that the turtles will move in a smaller or larger pattern, but rarely the actual emergent pattern of a pulsating circle. This illustrates one of the difficulties in understanding emergent systems. It is difficult to predict how a small change enacted by many agents will "integrate" to form a larger pattern. This is sometimes called "integrative understanding," as it parallels the cumulative integration of small differences in calculus.
Can you think of a real world system in which integrative understanding is difficult?
Changing Colors and Drawing Paths
You can change turtles' color with ask turtles [set color color], where color can be any of: grey, red, orange, brown, yellow, green, turquoise, cyan, sky, blue, violet, magenta and pink. There are other ways of representing colors with more flexibility described here in the NetLogo Programming Guide.
Try asking the turtles to pen-down. What happens? Try pen-erase and pen-up as well. If you want you can read about these commands here.
If you are using NetLogo Web, copy your code here, because when you leave this page the code you entered in the NetLogo Code tab won't be saved. If you are using NetLogo Desktop, still copy your code here, but you can also save your model on your computer if you want to.
If you had any issues on this page, describe them below. If not, type something like "no problems" and continue on.
This section will introduce you to patches, the second main element of NetLogo.
Changing Patch Color: pcolor
Patches form the background of any NetLogo model. Right now they are all black, so the "view" just looks like a big black box, but it is actually made of many patches. You can ask patches to do things just like you can ask turtles to.
Asking Neighbors for Things
Patches can ask other patches to do things (Turtles can too). This is one way to have patches interact with on another.
Procedures with Patches
Now you will write some procedures for patches.
Copy and paste your setup procedure below.
Go procedure
Copy the code of your go procedure below.
What behavior do you see? Why does this happen? Describe below.
If you had any issues on this page, describe them below. If not, type something like "no problems" and continue on.
The previous pages introduced you to turtles and patches and some of the things they can do. Turtles and patches are two of the types of agents in NetLogo. Agents are beings (in this case computational beings) that can follow instructions. The other two types of agents in NetLogo are links and the observer. We won't discuss links in this lesson. You can think of the observer as seeing things from your perspective. When you were typing commands into the command center, you were asking the observer to ask other agents to do things. Read the short section in the Programming Guide on agents to fill in a few pieces of information we haven't covered. You will also start getting familiarized with the Programming Guide, which will be very useful moving forward.
If you have time and want to, try creating a new NetLogo program using what you've learned. It doesn't have to be modeling anything necessarily, it could just be to make a cool visual effect. In fact, there is a whole branch of art that uses processes and algorithms to create artwork.
Next lesson we will start making models of natural phenomena. Whether you write a new program or not, please answer the last few questions below.
If you wrote a new program using what you learned, copy and paste your code below and describe in a couple sentences what you did. If not, just say why you didn't (e.g. busy, didn't think it would be valuable etc.)
Approximately how long did you spend on this entire lesson? How many sessions did you do it in?
Write a couple of sentences describing your experience with this lesson. What did you like and what do you think could be improved?