Meet AgentCubes: Spreading a Disease

AgentCubes · People who move, meet, and get sick

TipToday’s question

Put a crowd of healthy people in a room, add one sick person, and let everyone wander. How long until most of the room is sick? Today we’ll build that model in AgentCubes, where each person is an agent that follows its own simple rules.

NoteSoftware

Open AgentCubes Online at agentsheets.com in your browser and sign in with the class account I give you in class. There’s nothing to install.

A different kind of model

Back in Module 4.3, we modeled an outbreak with three numbers, \(S\), \(I\), and \(R\), and rates that said how fast people moved between them. That model never mentions a single person. It assumes everyone mixes with everyone else, all the time.

An agent-based model starts from the other end. We describe what one person does: where they walk, and what happens when they meet someone sick. Then we put many people in a world, run it, and watch what the whole crowd does. Nobody writes an equation for the outbreak; it emerges from the meetings.

AgentCubes vocabulary

Term Meaning
Agent One thing in the world that follows rules, here a person
Shape How an agent looks right now; a person can have a healthy shape and a sick shape
World The grid the agents live on
Rule An if–then pair: conditions on the left, actions on the right
Method A named list of rules, such as while-running, which runs every tick
Tick One time step: every agent runs its rules once

Build it

We’ll build this together:

  1. Make the agents. Create a person agent with two shapes, healthy and sick, and a floor agent.
  2. Paint the world. Cover it with floor, then place a crowd of healthy people with some space between them.

An AgentCubes world seen from above: a gray floor with twelve people standing apart, one of them sick, in the top-left corner.

The world from class: a dozen people on the floor, with one sick person in the top-left corner.
  1. Add one sick person. Change one person’s shape to sick.
  2. Write the rules. See below.
  3. Run it. Press the green run button and watch.

The rules

Here is the person’s while-running method from class. It runs once every tick.

AgentCubes rules for the person agent, while-running. Rule 1: if see healthy and next-to sick greater than 0, then change to sick. Rule 2: else if see healthy, then move-random-on floor. Rule 3: else if see sick and percent-chance 50, then move-random-on floor.

Read each rule as a sentence:

  1. If I’m healthy and at least one sick person is next to me, then I become sick.
  2. Otherwise, if I’m healthy, then I take one random step onto the floor.
  3. Otherwise, if I’m sick and a 50% chance comes up, then I take one random step onto the floor.

AgentCubes checks the rules from top to bottom and uses the first rule whose conditions are all true, just like if / else if in R. So a healthy person who catches the disease doesn’t also move that tick.

Rule 3 means a sick person moves only about half the time. Sick people slow down, which is one small assumption about how people behave.

move-random-on floor moves the person one cell in a random direction, but only onto floor, so two people never stand in the same cell. It’s the same idea as our random walk in Module 9.5, only now there are many walkers, and they affect each other.

Run it and watch

  • How does the sickness spread? Does it move like a wave, or jump around?
  • How long does it take for most of the people to get sick?
  • Run it again. Is the outbreak the same? Why not?

Make it more realistic

Change one thing at a time and run it again:

  • Not every meeting spreads disease. Right now, standing next to a sick person always makes you sick. Add a percent-chance condition to the first rule, such as percent-chance 20. How does that change the speed of the outbreak?
  • How sick people move. Change the 50 in rule 3 to 10, so sick people barely move, or to 100. Which spreads the disease faster? Why?
  • Crowding. Place twice as many people, or half as many. Does the disease spread faster in a crowd?
  • Recovery. Add a third shape, recovered, and a rule that changes a sick person to recovered with a small percent-chance. Now you have an agent-based version of the SIR model. Does a recovered person ever get sick again?
ImportantWhat we practiced
  • An agent-based model describes what each individual does, and the pattern for the whole group emerges.
  • An agent’s shape is its state, like a cell’s value in a grid.
  • Rules are checked in order, and the first true rule wins.
  • Chance and movement make every run different, so, as in Monte Carlo, one run is just one example.
Back to top