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:
- Make the agents. Create a person agent with two shapes, healthy and sick, and a floor agent.
- Paint the world. Cover it with floor, then place a crowd of healthy people with some space between them.

- Add one sick person. Change one person’s shape to sick.
- Write the rules. See below.
- 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.

Read each rule as a sentence:
- If I’m healthy and at least one sick person is next to me, then I become sick.
- Otherwise, if I’m healthy, then I take one random step onto the floor.
- 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-chancecondition to the first rule, such aspercent-chance 20. How does that change the speed of the outbreak? - How sick people move. Change the
50in rule 3 to10, so sick people barely move, or to100. 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?