POGIL 0 - Particles
Introduction
This POGIL was created by Eric Araújo (eric.araujo@calvin.edu) and is mostly based on the model from section 2.3 and 2.4 of the book Modeling Social Behavior by Paul E. Smaldino.
This activity will guide you through creating your first model after doing the tutorials on Netlogo’s website.
Student Learning Objectives: At the conclusion of this activity, students will be able to:
- Create a setup function and initialize the world for the Particles model.
- Create turtles representing the particles and program their movements and collisions within a torus world.
- Understand and implement the time counter of Netlogo (ticks), reset and increment the step counter.
- Use global variables to count collisions in this model and plot a graphic for the collions as a function of time.
Prerequisites: students should have gone through at least two out of the three Netlogo tutorials.
Process Skills Goals: Students will exercise:
- their capacity to implement a simple model in Netlogo
- determine meaning and understand a toy-model and its structures
Before you start, complete the form below to assign a role to each member. If you have only 3 people in your group, combine Presenter and Reflector.
Date | |
---|---|
Team Roles | Team Member |
Manager: reads the questions aloud, keeps track of time, and keeps the team moving quickly. | |
Presenter: talks to the instructor and other teams. | |
Recorder: records all answers & questions, and provides team reflection to team & instructor. | |
Reflector: Considers how the team could work and learn more effectively. Slows down the team if everyone is not understanding the answers. |
1. Description of the Particle World Model
The Particle World model is a simple agent-based model (ABM) designed to illustrate the fundamental concepts of building and analyzing ABMs. The model explores a hypothetical world populated by simple creatures called particles that move around constantly. The main research question the model aims to address is: How do factors like population density and “whimsy” (the randomness in a particle’s movement) affect the rate of collisions between particles?
Key Assumptions of the Model
To make the model manageable, several simplifying assumptions are made:
- Simple Environment: The particles live on a torus, a donut-shaped surface, represented in the model as a square grid with periodic boundaries. This means that a particle moving off one edge of the grid will reappear on the opposite edge. The torus shape is chosen to avoid edge effects and create a uniform environment.
- Basic Particle Behavior: Particles have two main properties: location and heading. They move continuously in their environment, changing their heading randomly based on the level of “whimsy”.
- Collisions: When two particles collide, they become disoriented and choose new, random headings. The model keeps track of the total number of collisions over time as a key outcome measure.
Why Particle World is Valuable
Despite its simplicity, the Particle World model offers several benefits:
- Focus on the Modeling Process: By starting with a simple, abstract model, the focus can be on learning the process of designing, building, and analyzing an ABM.
- Understanding Agent Dynamics: The model allows for exploration of how individual agent behavior (in this case, random movement with varying degrees of whimsy) can lead to emergent patterns at the population level (the rate of collisions).
- Foundation for More Complex Models: Particle World provides a foundation for building more complex and realistic ABMs by introducing the core concepts in a manageable way.
It is important to emphasize the need for a clear and unambiguous description, such as a formal model specification, to ensure consistency in interpretation and implementation for a first time model-creation process.
2. Coding the model
Open up a new NetLogo model.
We’ll start by adding a few buttons and sliders for some of the commands and variables we know we’ll need.
What sliders and buttons do you think are important to include in our interface?
What are sliders for? What are buttons for? (resist reading the next instruction…)
(really!)
We need
setup
andgo
buttons. Those will correspond to the procedures with the same name in our code. Add them.🔑 We need some sliders for the global parameters. Those will be:
- num-particles
- whimsy
- speed
Can you explain what each of these variables represent? Please report to the blackboard.
Increase the size of the grid by clicking on the
Settings
button. We are changing the grid from 33x33 to 101x101, so our agents have a lot of space.Go to the Code tab. We will start coding. Add your names in the code using comment lines. To do so, use semicolons.
NetLogo has the interesting feature that variables introduced in the Interface tab are treated as declared global variables, and so they do not need to be reintroduced in the Code window. In fact,there’s only one other global variable we need to declare. Can you guess which one? (think!)
- Add a global variable called
collisions
. Global variables are traditionally declared at the very top of the code, and so we can write the following:
[
globals
collisions]
- Next, we’ll write the code for the function to initialize the model, the
setup
procedure, using the primitive functionto
to introduce the definition of a new procedure. Write the following code down:
to setup-all ;; clear/reset all variables
clear
;; make the turtles look like arrows-default-shape turtles "default"
set
;; make a bunch of green turtles-turtles num-particles [
create
set color green2 ;; make them easier to see
set size -xcor random-ycor ;; give them a random location
setxy random360 ;; give them a random heading
set heading random ]
0 ;; initialize collisions to zero
set collisions -ticks ;; set the clock to zero
resetend
- Discuss about the block of codes for creating the turtles. What is going on in there?
- 🔑 This is the
setup
procedure. What are the main parts of the code that need initialization every time you start to run your model? Name 3 and report them in the blackboard.
- Go back to the interface (note that some error might pop up.Click again and it will change the tabs). Click on the
setup
button. What happened?
Now, we will code the model dynamics. They are laid out in the
go
procedure. Go back to the Code tab for that.Write down the following code:
to go[
ask turtles
;;turn a random amount
right random whimsy
left random whimsy
forward speed ;; move forward; if at least 1 other turtle near, set new headings
;if count turtles in-radius 1 > 1 [
in-radius 1 [
ask turtles 360
set heading random 0.1
fd ]
+ 1)
set collisions (collisions ]
]
tickend
- What is the line of code
right random whimsy
doing? Check the Netlogo dictionary to answer this question.
- Take a look at the command
count turtles in-radius 1 > 1
. This is inside a conditional statement, and should return true or false. In which conditions it will return true?
- 🔑 Where in this code we are taking care of the time aspect of our model? Report it in the blackboard.
- Let’s go back to the Interface tab. Click on
setup
button first and then click on thego
button. What happens if you click on thego
button before clicking on thesetup
button?
- How many times do we need to click in the
go
button to reach 1000 collisions? Do the test.
Now that you’ve wasted a bit of your terrestrial life clicking in the
go
buttom like crazy, change thego
button to run forever. To do so, right-click in thego
buttom, chose Edit, and then check the box that says Forever. Now hitsetup
andgo
.That is all the code you need to make the model work. Play around with it and see what kind of behavior you observe, fiddling with the various sliders in the Interface tab.
- We’ll do some work analyzing the model below. Before we move on, however, it’s worth saying something about code modularity. We have put all the model’s code in just two procedures:
setup
andgo
. It may seem economical to reduce the number of procedures in a program, but in fact the opposite is often preferable. By having many small procedures, code becomes more modular. Modular code is usually easier to read and debug, and code snippets are more likely to be directly transferable to another piece of software. Below, thego
procedure is rewritten to be more modular, supported by newly created supporting procedures:move
andbounce-turtle
.
to go[
ask turtles
move-turtle
bounce]
tickend
to move
right random whimsy
left random whimsy
forward speedend
-turtle
to bounceif count turtles in-radius 1 > 1 [
in-radius 1 [
ask turtles 360
set heading random 0.1
fd ]
+ 1)
set collisions (collisions ]
end
- Change your code to be modular. Can you see the benefits of breaking down the code into small procedures?
Now go back to the Interface tab and observe the simulation. Now you can see the agents move around and collide.
As you might have noticed, just watching the particles moving around and colliding is not enough if we want to answer our question. So let’s create a plot to show the collisions over time. Right-click on an empty area of the Interface tab and create a new plot. Since we have created a variable to count the number of collisions, we just need to plot this variable. Fill the
Pen updates commands
area withplot collisions
. That will do the job.🔑 Another way to retrieve the number of collisions is using a Monitor. Add a Monitor the same way you created a plot in the Interface tab by right-clicking and selecting Monitor. What should be put in the Reporter field of the Monitor? Report your answer in the blackboard.
- Now run the model, clicking on the
setup
button and then thego
button. You might observe the number of collisions increasing linearly with time. Let’s now think about the model itself. How whimsy the particles are affecting the amount of collisions? Can you tell by just ploting the number of collisions, or is there a better way? Discuss and come up with a simple equation that might help you compare different simulations with different values for the whimsyness of the particles. Don’t worry if this is too hard. Just try to ponder on what can be done for this specific situation.
- 🔑 Try to verify if density has more or less influence than whimsyness for this model. Play with the parameters and see the outcomes. Report in the blackboard which of the factors influence more the number of collisions: density or whimsyness?