Supermarket Simulation Shows the Importance of Social Distancing to Contain Covid-19 Spread

An interactive supermarket simulation showing how important social distancing is for containing the spread of Covid-19

Overview

There is no doubt that Covid-19 has spread like wildfire and wreaked havoc on our lives. In just four weeks, our way of life has become very different from what it used to be. To stop the spread of the virus, countries are imposing preventative measures. The majority have closed their borders, internationally and state-wide, and many others such as Australia and New Zealand have imposed a lockdown, closing non-essential businesses and venues such as cinemas, pubs, restaurants, parks and playgrounds. Only essential businesses like supermarkets, childcare facilities and chemists can remain open.

All of these measures impose a strategy called social distancing, a term we may not have heard until just a few weeks ago, thanks to Covid-19.

Social Distancing

Social distancing refers to efforts to avoid direct or close contact with a person while they are infectious. Because some who are infected do not show symptoms, we should assume that everyone is contagious. For example, when you are at the supermarket buying groceries — which is practically the only reason I went out in the past three weeks — you should maintain a distance of at least 1.5 metres from others. This is crucial because the virus can spread from water droplets expelled when breathing, sneezing or coughing. Hence, the closer you are, the higher your chances of infection.

Social distancing — 1.5m safe distance between each other

In order to better understand and do my part by encouraging others to see the importance of social distancing practices, I built an interactive simulation using JavaScript and a matter.js physics engine. It uses a particle system to simulate two levels of social distance compliance and compares their final infection rates.

For the tech wiz, the link to the simulation and the source code is provided at the end of the blog so you can play around with it yourself.

Simulation

The simulation tries to emulate a scenario at the supermarket in which people enter and exit the store at regular intervals. Each person enters and randomly visits six stalls: meat, veggies, fruit, snacks, milk and the infamous toilet rolls before exiting the store. At any given time, we restrict the number of people who can enter the store with a customisable number. There are two different social distance compliance settings: poor, when people ignore social distancing and might bump into each other, and good, when people try their best to maintain a safe distance from each other.

It also lets you control the number of sick people who enter the store. When a healthy person falls within the infection radius of a sick person, he or she has a 10% chance to be infected and, if contaminated, will be able to infect others right away.

Covid-19 Social Distancing Simulation

The simulation will run for about 45 seconds, and on completion, it will show the infection rate, which is the number of newly infected people over the number of healthy persons who enter the supermarket.

Note that, to simplify things and to make the simulation duration short enough to watch and enjoy, some of the parameters used are not an accurate clinical number. Hence, the simulation infection rate produced will be higher than the actual rate. Since this exaggeration affects both poor and good social distance compliance (SDC) groups equally, it works just fine for giving us an idea of how much different SDCs impact infection rates.

I am going to run you through two different kinds of experiments:

  • Social distancing compliance, to show the infection rate comparison between poor and good SDC.
  • Maximum person on site limit, to show how important it is to impose this limit for social distancing strategies to be effective.

Without further ado, let’s go through each experiment.

Social Distance Compliance (SDC)

The goal of this experiment is to demonstrate the difference in infection rates between the poor and good SDC. To accomplish this, I run the simulation twice (first with poor SDC and second with good SDC) with the following common parameters:

  • One out of 10 people who enter are sick.
  • Restrict the number of people to enter to 10 at a given time.

As seen in the video below, the poor SDC run shows a higher infection rate of 54% as opposed to the good SDC run rate of 4%. In the poor SDC run, people often bump into each other and get infected. However, in the good SDC run, people try to maintain a safe distance from each other, though this is sometimes impossible when too many people are around, leaving no room for social distancing; so infection still occurs, but far less often.

Comparison between good SDC and poor SDC

You can also run the simulation yourself on your web browser from the links below. Note that you will not get the same result as me because of the random nature of the simulation. However, averaging the results from multiple runs will get you a more accurate and stable result, which is exactly how I evaluated my experiment.

Maximum Person on Site Limit (MPOSL)

The second experiment tries to assess how effective a social distancing strategy is in an overcrowded space. For this, I execute four pairs of experiments wherein the numbers of people who can enter at a time are 10, 25, 35 and 50. Each experiment pair consist of 20 sub-experiments that are equally divided into two groups. The first group exercise poor SDC and the other exercise good SDC. The average result (infection rate) of each group is used as the final evaluation metric in order to mitigate the random nature of the simulation.

The video below shows part of the experiment. You can see that the higher the number of persons, the harder it is to maintain a safe distance from others (even with good SDC) as there is not much room to move. Hence, people often bump into each other and get infected.

Impact of various values of MPOSL on good SDC and poor SDC

The chart below shows that infection rates in good SDC runs increase significantly as the MPOSL increases from 5% at 10 MPOSL to 64% at 50 MPOSL. This indicates that the social distancing strategy is less effective in an overcrowded place.

Infection rates at different values of MPOSL

You can also run each simulation yourself by clicking the links below.

Summary

We have seen that social distancing is very critical for helping us stop the spread of this virus. Dropping an infection rate from 55% to 5% is a massive leap. To put this into perspective, a daily rate of 5% on a population with 100 infected people yields 280 infected after 21 days, whereas a rate of 55% yields 1 million infected!

Comparison on number of infected between good SDC vs poor SDC

Granted, our simulator exaggerates to an extent. However, even with a 27% infection rate, there will be approximately 15,000 infected people; 54 times more than 280 people, what is estimated if we exercise good social distancing.

We can also see that a good social distancing strategy won’t be effective in an overcrowded place. This is why governments close venues such as pubs, sports events, swimming pools and gyms. Similarly, supermarkets in Australia are also starting to limit the number of people who can enter at a time.

Hopefully, this blog provides useful insights. If it does, please share it with as many people as possible to help them take social distancing more seriously so we can beat Covid-19 as quickly as possible and go back to our normal way of life.

The code for this project is available here. You can also play with the simulator directly on your web browser.

Please stay safe and away from each other! …at least for now :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store