A graphical simulator of Covid-19
Abstract
In this project, we have built a simulator that replicates the spread of a coronavirus-like infectious disease, with the aim of making an educational, user-friendly application that allows people to learn the basics of infectious diseases and confinement measures. We also show that higher population densities lead to greater and faster virus propagation, that quarantines are only effective at reducing the spread of the virus when applied to a high percentage of new infected cases, and that confinement measures are an effective solution to contain the spread of a virus.
Full text
A graphical simulator of Covid-19∗ ´ Oscar Cordero†and V´ıctor Peris‡ Enginyeria F´ısica, ETSETB, Universitat Polit`ecnica de Catalunya (Dated: June 19, 2020) In this project, we have built a simulator that replicates the spread of a coronavirus-like infectious disease, with the aim of making an educational, user-friendly application that allows people to learn the basics of infectious diseases and confinement measures. We also show that higher population densities lead to greater and faster virus propagation, that quarantines are only effective at reducing the spread of the virus when applied to a high percentage of new infected cases, and that confinement measures are an effective solution to contain the spread of a virus. I. Introduction A few weeks into 2020, a newly discovered virus from China had spread to other countries in the developed world and by early March, the newly named Covid-19 had caused the lockdown of most of the world’s nations. Beyond the scientific interest of accurately reproducing and predicting the spread of Covid-19 [1][2], simulations can be used for the broader purpose of educating the general population on the different effects that certain measures and policies have in containing or favoring the spread of an infectious disease [3]. The aim of this project is to create a simple, user friendly, graphical user interface that allows the user to fiddle with parameters such as confinement and quarantine rates, population density or the infection rate, to allow anyone to better understand the means by which infectious diseases can spread in a popuation. II. The code In this section we shall explain the structure of the code behind the simulation, both at a computational and graphical level. All code has been written using Python 3.6, for its open-source nature and flexibility. On the one hand, at the computational level, we create the main variables, which include sets of people, divided into 3 different categories: susceptible, infected and recuperated. The simulation starts with a total population and an initial percentage of people infected, and finishes when the simulation time reaches the total simulation time. We also define some parameters, explained in the next section, which allow us to simulate in a way similar to the current world situation. The main code goes through all susceptible people for the specified unit of time, 1 hour in our case, and checks if the person is confined; if they are, then it advances to the next susceptible person; if they are not, the person ∗An individual based simulator with a graphical user interface that simulates the spread of a Covid-19 type virus. †Also at Centre de Formaci´o Interdisciplin`aria Superior (CFIS), UPC; oscar cordero b[email protected] ‡Also at Centre de Formaci´o Interdisciplin`aria Superior (CFIS), UPC; v.p[email protected] will move, and the code will call on all infected people who are not quarantined, one by one, and check if the distance to them is smaller than the radius of influence of the virus, and also whether a random number is smaller than the infection rate. If both are true, the susceptible person becomes quarantine-infected, with a certain quarantining probability, or non-quarantine- infected with the complementary probability. Then, for every infected person the code goes through, it will generate a random number: if it is larger than the recovery rate, the infected person becomes recuperated; however, if it is not, the infected person will move and will be able to infect other people in the next time step. We show in Figure 2 a flowchart that aimes to make the previous explanation more understandable. In blue and green we can see when the susceptible and infected loops finish, respectively. In yellow we see the what is explained in the previous paragraph, whether the code moves the infected people, or else the infected people become recuperated. Finally, in red, we see when all these secondary loops are finished, at which point the code will add 1 hour to the total time simulation, and repeat again the whole process. Figure 1: Example of the graphical interface. Upper graph: the parameter interface (sliders control the value of each parameter). Lower graph: evolution of all 3 sets of people during with time.
2 Figure 2: Flowchart of the simulation When the simulation time reaches the confinement end date, as in Figure 2 (top-left), all susceptible people will no longer be confined, and the infection rate might be reduced, due to people’s awareness. On the other hand, at a graphical level, we have created a simple square geometry where people move freely around, and some external code which allows us to set people back inside the geometry, if their next position in time falls out of the square. In the bottom-left graph of Figure 1 the susceptible, infected and recuperated sets of people are graphed in blue, red and green, respectively, as dots. People will move randomly with a specific velocity but in a random direction and for a random initial position, which will create different unique paths for all of them. The bottom-right graph shows the evolution of all 3 sets of people with time, which will allow us to discuss some interesting results, as seen in the following sections. III. Playing with the simulation As explained, the aim of this project is to build an applet that can be used by anyone to fiddle with the parameters that govern the spread of a virus. In this section we shall see the effects of those parameters included in our simulation, and some typical combinations that try to reproduce real-world results. A. The parameters Figure 1 top, shows some parameters of the graphical interface with the main options explained below. 1. Total Population [500-1500] This parameter controls how many individuals are used in the simulation. Lower values lead to a faster simulation speed, whereas higher values give better statistical results. This parameter is meant to be used as a compromise between CPU usage and the effects of noise, and users can change it as needed. 2. Initially Infected Population (% of total) [1-50] The user might not be interested in always starting a simulation with the same initial conditions (i.e.: seeing just the latter stages of the virus spread without going through the initial phase). Also, with this parameter the user can check the effects of the size of the initial outbreak on the spread of the virus (i.e.: is it the same if a country first makes contact with the virus through a single individual arrived by plane as if it makes first contact through a full cruiseship filled with infected people?). 3. Simulation Time (in days) [40-125] This allows the user to change the length of the simulation. This might be useful to save on computational time, or to stop the program from plotting irrelevant results once populations have stabilized within the system. 4. Population density (hab./dist.2) [5-150] This parameter controls how densely populated the simulation space is. As we shall see, this has one obvious effect: sparser populations, the virus spreads slower than it does in city-like densely populated areas. 5. Percentage of people initially in quarantine or confinement (% of total) [1-100] These parameters allow for the confinement/quarantine of part of the susceptible/infected population from the start of the simulation. Anyone who is confined/quarantined cannot get infected/infect. This is meant to help the user understand the effectiveness of putting the sick and the healthy in isolation from the rest of the population. 6. Quarantine rate of success upon infection (% of total) [1-100] This option allows the user to control what percentage of new infected patients are correctly identified and duly put in isolation to prevent them from spreading the disease. 7. Confinement end-date (in days from start of the simulation) [5-125] and Reduction in infection rates (%) [0-100] These parameters are used in combination to dictate the terms of the deconfinement process. The user can choose a time at which all susceptible people in the confined category suddenly become deconfined and can start moving around and getting infected. This is intended to mimick the real-world process of deconfinement that some countries are following after months
3 of nationwide lockdown. The user can also control whether there is a reduction in infection rates after deconfinement, and to which degree. This is intended to reproduce both the gradual nature of deconfinement in the real world (as people are not suddenly released back into society all at once), or the self-consciousness of people, acquired during the confinement time: most acquire a sense of danger that makes them more careful of the people around them once they are allowed back outside, either through social distancing, hand-washing, masks or other safety and hygiene measures. B. Understanding different strategies Figure 3: Evolution of the susceptible (blue), infected (red) and recovered (green) populations for the following densities: 10 hab./dist.2(top-left), 35 hab./dist.2(top-right), 65 hab./dist.2(bottom-left), 150 hab./dist.2(bottom-right). Now we can look at the different ways in which the virus can propagate by fiddling with the parameters described previously. For all simulations we will use the maximimum amount of total population, N= 1500, in order to get the least amount of statistical noise. 1. Population Density Let’s first look at the most basic of possibilites: one where there is no confinement nor quarantine, where the virus is free to infect everyone as much as it can. In this scenario, there are only two factors at play: initial proportion of infected people and population density. Let us explore the effects of population density, with the initial infected population constant at 1% for all simulations. The effects of population density become clear if we look at the results in Figure 3. For the lowest densities, ρ= 10 hab./dist.2, the population of infected people decreases, without ever catching an upward trend: people are too far apart and infected people recover before they have the chance to infect others, and the vast majority of the population remains uninfected at the end of the simulation. For ρ= 35 hab./dist.2we see a small peak of infected appears, but it is mostly flat and around 25% of people remain uninfected as the virus dies off. For ρ= 65 hab./dist.2we see that most people are infected, and the infected peak is mostly symmetrical: the rate of growth of infected people is as fast as the later decay from infected to recovered. For the highest density, ρ= 150 hab./dist.2, though, we see a very sharp spike in the number of infected cases which then comes back down a bit slower: that is, the virus infects everyone as fast as it can, since population is very densely packed and people remain in close contact with each other, and then dies off as it has no new people to infect. C. Efect of quarantine Figure 4: Evolution of the susceptible (blue), infected (red) and recovered (green) populations for an effective quarantine of 90% of those initially infected, for a density ρ= 150 hab./dist.2. Figure 4 shows the effects of quarantining the first group of infected patients who arrive in densely populated (ρ= 150 hab./dist.2) areas. In this case, quarantine affects 90% of the initially infected patients (1% of the total, as in previous simulations). We see that, despite there being an initial buffer on the rise of infected people, after some time we get a similar peak to the one from figure 3 (bottom), but shifted back in time. This is because, even if most of the initial infected are effectively put in quarantine, the very few who go unnoticed under the radar are enough to kickstart the virus spread, since once they start infecting people, those who had been originally quarantined now have no effect on the total development of the virus. This exemplifies what happened in some countries, where even after a rigorous quarantine of their first known Covid-19 cases, still cases skyrocketed, because there is no way to guarantee that the quarantine is perfect and whatever infected people go unnoticed will still cause mayhem. If we do not just quarantine those initially infected, but also a certain percentage of those who become infected later on, spreading out the infection peak over time is possible, but only acheivable for high enoug quarantine rates. Figure 5 shows two of these cases: one where 30% of new cases are quarantined, and one where 70% of them are. As can be seen, if the quarantining rate is not high enough, the virus spreads unstopped as if nothing was being done, and only through strict control of a large enough portion of the population is it possible to control the spread of the virus. Effectively quarantining large portions of the population is extremely innefficient
4 and ineffective. As most countries have learnt, confining those who are still susceptible is a much more efficient and easier way of slowing the spread of the virus. We shall explore this option in the next section. Figure 5: Evolution of the susceptible (blue), infected (red) and recovered (green) populations for an effective quarantine of 90% of those initially infected, for a density ρ= 150 hab./dist.2, and quarantines of 30% (left) and 70% (right) of those infected thereafter, respectively. 1. Confinement Measures Figure 6: Evolution of the susceptible (blue), infected (red) and recovered (green) populations after confinement measures are lifted on day 65, for ρ= 90 hab./dist.2. Left is for no initial confinement, right is for initial ocnfinement measures.. Figure 6 shows the difference between confining 50% of the people and lifting measures on day 65, by which time the virus has practically disappeared, and having no confinement measures at all. As we can see in the first case, practically the entire population is infected, which indicates the importance of confining. We have seen that quarantining the infected population is a conceiveable, albeit extremely inefficient, way of controlling the virus’ spread. A much more efficient way of doing it is through confinement of the population. This consists on reducing population movement amongst those who are susceptible, to reduce the speed at which the virus can spread. In our simulations, we have represented this by anchoring a certaing percentage of susceptibles in place and removing the possibility that they become infected. In all of the following simulations, we will initially confine 50% of the population, and confinement measures will be lifted at some point during the simulations. In Figure 6 right, confinement measures are lifted on day 65. As the virus is already dead by this point, lifting confinement measures does not cause any raise in the number of infected cases. This would be the ideal situation, where confinement measures are lifted once the virus is completely gone, but it is not what happens in reality, which affects virus spread negatively, as we shall see. Figure 7: Evolution of the susceptible (blue), infected (red) and recovered (green) populations after confinement measures are lifted on day 42, for ρ= 90 hab./dist.2hab./dist.2. Left shows no reduction in infection rates, right shows a reduction of 50% in infection rates. Figure 7 shows what happens when people are deconfined before the virus is extinct. If people are deconfined with no restrictions, then the few people who are still infected start infecting those who have just deconfined and a second wave of infections apears, which can be just as bad or, as is the case in figure 7 (left), even worse than the first one. Instead, if after confinement people are more self-conscious about issues like hygiene or social distancing, or that deconfinement comes with some restrictions for those who go out, such that infection rates after deconfinement drop by a certain amount. Then a second wave might still appear, but usually in a much milder and more spread-out and controlled manner, as is the case in figure 7 (right). IV. Conclusions In this project we have built a simple simulator with a user-friendly GUI capable of reproducing some real-life results, and study the effects of quarantines and confinements. A simple simulator with graphical capabilites might prove very useful in bringing knowledge to the general public, and we have shown that it is possible to build one that is simple but complete enough to be able to accomplish this task. Our results have shown that population density plays a big role in the spread of a virus, that initial quarantines have no noticeable effect if they are imperfect, unlike furhter quarantining of new cases, which can be effective if done extensively. Our findings also support the idea that confinement measures are an effective way of containing the virus, and that lifting them too soon might lead to secondary outbreaks. V. References [1] Adam D. (2020). The simulations driving the world’s response to COVID-19.Nature,580, 316-318 [2] Fern´andez J. and Charles I. Jones (2020). Estimating and simulating a SIRD model of Covid-19 for many countries, states and cities.National Bureau of Economic Research:, 27128 [3] Silva P. (2020). Agent-Based Simulation of COVID- 19 Health and Economic Effects. Towards Data Science