POGIL 0 - Particles

Particles colliding

Here is the image capturing two particles in the moment of collision, with trails and energy bursts highlighting the impact.

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

A ring torus with a selection of circles on its surface (From Wikipedia)

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.

  1. What sliders and buttons do you think are important to include in our interface?









  2. What are sliders for? What are buttons for? (resist reading the next instruction…)





























(really!)



























  1. We need setup and go buttons. Those will correspond to the procedures with the same name in our code. Add them.

  2. 🔑 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.





















  1. 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.

  2. Go to the Code tab. We will start coding. Add your names in the code using comment lines. To do so, use semicolons.

  3. 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!)

















  1. 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
]
  1. Next, we’ll write the code for the function to initialize the model, the setup procedure, using the primitive function to to introduce the definition of a new procedure. Write the following code down:
to setup
    clear-all ;; clear/reset all variables
    ;; make the turtles look like arrows
    set-default-shape turtles "default"
    ;; make a bunch of green turtles
    create-turtles num-particles [
        set color green
        set size 2 ;; make them easier to see
        setxy random-xcor random-ycor  ;; give them a random location
        set heading random 360  ;; give them a random heading
    ]
    set collisions 0 ;; initialize collisions to zero
    reset-ticks ;; set the clock to zero
end
  1. Discuss about the block of codes for creating the turtles. What is going on in there?









  1. 🔑 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.





















  1. 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?









  1. Now, we will code the model dynamics. They are laid out in the go procedure. Go back to the Code tab for that.

  2. 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 [
            ask turtles in-radius 1 [
                set heading random 360
                fd 0.1
            ]
            set collisions (collisions + 1)
        ]
    ]
    tick
end
  1. What is the line of code right random whimsy doing? Check the Netlogo dictionary to answer this question.















  1. 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?











  1. 🔑 Where in this code we are taking care of the time aspect of our model? Report it in the blackboard.









  1. Let’s go back to the Interface tab. Click on setup button first and then click on the go button. What happens if you click on the go button before clicking on the setup button?







  1. How many times do we need to click in the go button to reach 1000 collisions? Do the test.







  1. Now that you’ve wasted a bit of your terrestrial life clicking in the go buttom like crazy, change the go button to run forever. To do so, right-click in the go buttom, chose Edit, and then check the box that says Forever. Now hit setup and go.

  2. 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.















  1. 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 and go. 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, the go procedure is rewritten to be more modular, supported by newly created supporting procedures: move and bounce-turtle.
to go
    ask turtles [
        move
        bounce-turtle
    ]
    tick
end

to move
    right random whimsy
    left random whimsy
    forward speed
end

to bounce-turtle
    if count turtles in-radius 1 > 1 [
        ask turtles in-radius 1 [
            set heading random 360
            fd 0.1
        ]
        set collisions (collisions + 1)
    ]
end
  1. Change your code to be modular. Can you see the benefits of breaking down the code into small procedures?



  1. Now go back to the Interface tab and observe the simulation. Now you can see the agents move around and collide.

  2. 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 with plot collisions. That will do the job.

  3. 🔑 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.







  1. Now run the model, clicking on the setup button and then the go 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.





  1. 🔑 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?