Contagion Simulator.
This work was undertaken as a final project in the Yale School of Architecture graduate course Design Computation in the spring of 2020 (remote classes). This simulation was designed in Processing.
Taking inspiration from visual aids developed by the Washington Post (here and here) to explain the spread of COVID-19, I wanted to create a tool that helped people understand the viral contagion as well as see how changing different parameters (social distancing, quarantining, etc.) could change the course of a pandemic.
Demos
How it works
Every agent, regardless of their type, has a set of characteristics including
a radius
a speed in the x-direction
a speed in the y-direction
a ‘state’ value
a random starting position (x-coordinate and y-coordinate)
a ‘sick counter’ value
A healthy agent has a sick counter value of 1000 and a state value of 1, meaning healthy.
As it moves, it detects whether other agents are nearby and will rebound if the two agents collide, preserving momentum. It will also detect screen boundaries and rebound if it hits an edge. However, whether an agent moves is dependent on whether or not the agent is physical distancing, which we can control later.
Each healthy agent is constantly checking every other agent to see if they are sick. Not every agent who comes into contact with a sick agent will become infected; it depends on the contact rate. This rate is defined as a percentage, or a figure between 0 (meaning no contacts result in illness) and 1 (meaning all contacts result in illness).
If a healthy agent detects a sick agent, it will randomly generate a number between 0 and 1. If this number is below or equal to the contact rate, then the agent will contract the illness, and become sick.
In this simulation, a random agent is made ‘sick’ with the press of the ‘s’ key.
Once the illness is contracted, the state of the agent changes to 2, meaning sick and contagious. At this time, incubation (the time of contracting the illness before symptoms are shown) begins. This is reflected in the sick counter: it will begin a countdown from 1000. From a sick counter value of 999 to 850 (which is approximately 5 seconds in this simulation), the agent is in incubation and shows no symptoms. When incubation is over, symptoms arise, and the agent will stop moving to simulate taking sick leave and staying home. The agent will now fight the disease from the sick counter value of 849 to 1 (about 20 seconds).
Because they are now contagious, sick agents will display a minimum distance radius. If a healthy agent comes within this radius, they are at risk of become infected, as previously described.
On the other hand, sick agents no longer detect whether those around them are sick. This prevents their sick counter from restarting if they come into contact with another sick agent.
Once the sick counter has reached 0, the agent will either recover or become deceased. This depends on the recovery rate, a number between 0 (no agent recovers) and 1 (all agents recover). At this point, the sick agent will randomly generate a number, and if it is below the recover rate, the agent will recover.
If an agent recovers, its sick counter will return to the healthy amount of 1000 and its state will become 3, to indicate it is a recovered agent. This agent will begin to move around again, lose its minimum distance radius, detect sick agents just like a healthy agent, but will only become reinfected depending on the reinfection rate, which determines how likely an agent is to contract the illness after already having recovered. Since not all diseases produce immunity in recovered people, some will be at risk of contracting the illness again. If an agent contracts the illness again, it will become a sick agent just as if it had never been sick before.
If, once the sick counter has reached 0, the random number generated is above that of the recovery rate, then the agent will become a deceased agent. This sets their sick counter at 0, and their state at 4, meaning deceased.
Deceased agents no longer move—they remain where they were throughout their quarantine. However, other agents can still bounce off them.
Deceased agents do not check if other agents are contagious, and cannot become sick.
Other metrics that can be controlled are:
Population: entered at the beginning of the simulation.
Presence of sick agents: added at any time in the simulation by pressing the ‘s’ key per sick agent.
This simulation is helpful because it allows the user to manipulate the outcomes by changing various parameters.
These include:
Minimum distance: the distance it takes for a healthy agent to be at risk of contracting the illness from a sick agent.
Recovery rate: the rate at which sick agents will become recovered agents.
Contact rate: the rate at which healthy agents will become sick agents after coming into contact with sick agents.
Reinfection rate: the rate at which recovered agents will become sick agents after coming into contact with sick agents.
Physical distancing: the speed at which agents move around with 0 meaning full speed and 1 meaning everyone is quarantined.