CSE 30 -- Prog 2

Due: 11:59pm Sunday, May 10, 2020 (Pacific time) -- Simplified Scenario 1
Due: 11:59pm Sunday, May 17, 2020 (Pacific time) -- Original Full Specs
Late submissions will not be accepted/graded.

Learning Objectives:

Write your own class (Dot) and create simulations using pygame to model the spread of COVID-19, under certain assumptions in a hypothetical situation.

Description:

The goal of this assignment is to create simulations using the PyGame library to study how the coronavirus spreads in a hypothetical population. We would like to model the spread of the disease, and how sheltering-in-place (SIP) and social distancing (SD6) affect the spread of the disease. We will be creating 2D simulations similar to (but not quite the same) the ones in this article on Why outbreaks like coronavirus spread exponentially, and how to ''flatten the curve''.

The simulations we will create are 2D animations, where a dot represents a person. We will use dots and persons interchangeably from here on. You may use a dot size of 5, and a screen size of height and width set to be at least 500 X 500.

The inhabitants are spread across the area of the town (a 2D screen), and move around town as they go about their regular business. Each dot has an initial position (denoting the location of their home). We assume each person lives independently, and no one shares a home. Therefore, as we generate each dot, we must ensure that the new dot doesn't coincide with any of the previous dots. Each dot also has a random target position (denoting place of work), and they travel back and forth between the initial and target positions. You will probably need to also keep track of the dot's current position. For the purposes of our simulation, we will assume that 20 frames of simulation time is 1 day.

The virus spreads (via droplets) when an infected person comes in close contact (within 6 feet) of another person who has the virus. Hence, a critical component of our simulation involve: collision detection and collision avoidance. A collision occurs when 2 dots come in contact with each other (when there is no 6 feet social distancing SD6) or, when their 3 feet radius "bubbles" come in contact (when there is SD6). Collision detection is provided by PyGame's sprites, and you are encouraged to use those methods. Collision avoidance is the behavior that is adopted when a collision is imminent. In the Washington Post link above, the movement of the dots behave like bouncing balls. That is, when a collision is imminent, the collision avoidance strategy is to go in the opposite direction. For our assignment, we will try to make a more realistic collision avoidance strategy. When a collision is imminent, we allow one of the dots to go ahead, and if necessary, to slightly modify its course, while the other dot(s) wait until it's clear to proceed in their own path(s). Who goes first is decided by a coin toss i.e. uniform random draw. In situations where the collision is with a stationary dot, it is incumbent upon the moving dot to make evasive manuevers. The only exception is collision with a stationary dead dot, in which case the moving dot can simply proceed in its path as if the dead dot does not exist.

There are 2 types of dots: a carrier or non-carrier of the virus. COVID-19 spreads through close contact with a person carrying the virus, a carrier. Non-carriers can't trasmit the disease. Associated with these two types are 5 different states that a dot can be in. A carrier dot can be in one of the following 2 states: infected (but not sick i.e. asymptomatic), or sick. A non-carrier dot can be in 3 states: unexposed, dead, or immune.

The states (with a distinct color for the dot representing the state) are described as the following:
  1. Unexposed (BLUE): The people who haven't encountered the virus at all so far.
  2. Infected ((ORANGE): People who have the virus but have no symptoms of the disease. An unexposed person has an 80% chance of getting infected on coming in contact with a person carrying the virus. An infected person may either get sick with symptoms in 5 days, or stay infected (contagious) for a period of 15 days and thereafter develop immunity to the disease.
  3. Sick ((RED): People who have the virus and are sick with symptoms. Sick dots do not move and become stationary until they recover and become immune, or until they die. Of those infected, 50% get sick with the disease. In 10 days, a sick person may either recover completely (98%) and develop lifelong immunity, or die (2%).
  4. Dead ((BLACK) : People who die from the disease. 2% of the sick die. Dead dots do not move and do not infect other dots anymore.
  5. Immune ((GREEN): There are three ways of getting to this state: 1) People who got sick with COVID-19, and recovered and thereby, have developed lifelong immunity. 2) People who were infected but didn't develop symptoms, and became immune once they stopped being contagious. 3) We assume that 5% of the entire population was naturally immune to the disease to begin with, and can't be affected by the virus at all.
On day 1, one (random) person returned to the town from elsewhere, and is sick with the virus. Unexposed people who come in contact (collision) with this carrier as they travel between home and work may become infected with the virus. There is an 80% chance of contracting the virus (and changing state to infected) on collision with a carrier. We assume that this is the only means by which an unexposed person may contract the virus, and they are infected immediately upon collision. To summarize, the following transitions between states are possible:
  1. unexposed infected (happens immediately after each collision with 80% chance)
  2. infected sick (after 5 days of getting infected with 50% chance)
  3. infected immune (after 15 days of getting infected with 50% chance)
  4. sick immune (after 10 days of getting sick with 98% chance)
  5. sick dead (after 10 days of getting sick with 2% chance)
Therefore, unexposed, infected and sick are changeable states, while dead and immune are final states, i.e., the dots don't transition any further once they arrive at these states.

We would like to create animations for 3 different scenarios:

Scenario 1: No regulations in effect
On day 1, one random dot is sick and starts to infect the others it comes in contact with. COVID-19 spreads unrestricted. Dots in all states move around except for those that are they are sick or dead. The dead dots are inactive, which means they are stationary, and play no further part in the spread of the disease. The sick dots are stationary for the duration of time they are sick. Friends (other dots) may still visit (i.e. collide with) them and potentially get infected. Therefore, we can expect that after a certain amount of time passes, all the people are either immune or dead from COVID-19, unless they have somehow managed to remain unexposed.

Simplified Scenario 1: No regulations in effect
Same as above, but you don't need to worry about checking if dots come within 6 feet of each other. This means that for infection to happen, collision must happen between dots. That is, a dot needs to be right next to another dot for any chance of infection. This change will result in less dots getting infected, and more dots being left unexposed.

Scenario 2: 6 feet Social Distancing (SD6) in effect
On day 1, social distancing guidelines are enforced, and a single random sick dot who does not follow SD6 starts the spread of the virus as in scenario 1. 90% of the population follow the SD6 order sincerely, while the remaining 10% don't follow them at all. This property is fixed at the start of the simulation, and is independent of the state of each dot. So, a dot that follows SD6 will always follow it even when it changes state. Likewise, a dot that does not follow SD6 will always not follow it.

To represent social distancing graphically, each dot who practices social distancing will have a protective bubble around it, while those who don't observe social distancing will not have the protective bubble. To create the bubble, use a larger circle to represent a 3 feet radius around each dot. Use a size that is 3 times larger than the dot i.e. 15 for a dot of size 5.

The unexposed dots that are practicing social distancing can't get infected even on collision with a carrier as long as the collision stops at a distance of 6 feet or more. For dots not practicing social distancing, all the assumptions from scenario 1 hold true, and therefore COVID-19 continues spreading, but hopefully, at a slower pace.

Scenario 3: SD6 and shelter-in-place (SIP) in effect
On day 1, social distancing and SIP directives are enforced. Again one random sick dot who does not follow SIP nor SD6 starts the spread of the virus. 75% of the population follow the SIP order, while 25% don't. The dots practicing SIP remain stationary.

Everyone who follows SIP also follows SD6. Therefore, they can't contract the virus even if a carrier collides with their protective bubble.

Of the 25% of the population that don't practice SIP, all the assumptions from scenario 2 hold. (Of the non-SIP population, 90% follow SD6 and 10% don't.) Therefore, we can expect the spread of COVID-19 to be further contained.

Suggested Steps:

As you can see this is a LONG assignment. Please plan accordingly and START EARLY. Assuming that most of you have some background on python classes, here're some suggested steps that you can take to tackle this assignment one piece at a time:

Bonus 1: (10)

Create the colored stacked histogram as time progresses showing the different curves for each of the 3 scenarios. These curves are similar to those in the Washington Post simulations, although you'll need 5 colors (blue, orange, red, black, green). Note: you can use turtle graphics, pygame.draw.rect, or matplotlib to create the graphics.

Bonus 2A: Analysis (10)

You need to complete Bonus 1 to be eligible for this bonus. Requires extra coding and report. Perform analysis on the simulations and include answers to the following questions: (a) How does population density affect the spread of the virus? You can vary the density by adjusting the number of dots and/or the screen size. Note that you don't want to have less than 100 dots in your population or you will see more fluctuations in your experiments. Run each setup (population / screen size combination) several times and report on their average results. (b) What percentage of the population need to be non-carriers (unexposed + natural immunity + immunity after recovery) before the infection rate has leveled off -- "close to zero for a few frames". Note that the derivative of the number of new infections per frame is positive when infections are still increasing; becomes negative when infections are decreasing; and zero when there's no change in number of infections. How many ticks from start of the simulation before this happens, if ever? You will need to study this under the 3 different scenarios above i.e. 6 answers. Your report should include discussions and supporting images for your findings.

Bonus 2B: Variations (10)

You need to complete Bonus 1 to be eligible for this bonus. Requires extra coding and report. The scenarios described above are not realistic. You will study variations on 2 different aspects: (a) For scenarios 2 and 3, study the effects of a delayed implementation of the guidelines (SD6, and SIP + SD6). For example, what happens if dots move freely for a while before guidelines are implemented. For this question, study and report the effects under different amounts of delay. (b) Here, we will study the effects of easing restrictions at different stages. To simplify things a bit, consider scenario 3 above with implementations from day 1. But both guidelines are lifted at 3 different stages. In the first case, guidelines are lifted right at the peak of the infection rate -- local maxima of the infection curve. In the second case, guidelines are lifted prematurely when the infection rate is halfway up the peak. And in the third case, guidelines are lifted after the infection rate has leveled off. Your report should include discussions and supporting images for your findings.

Resources:

Here is the main reference link for pygame Additional links for getting up to speed with pygames are in the class url under PyGames

Rubric:

Class attributes/methods: 20%
Scenario 1: 20% each
Scenario 2: 20% each
Scenario 3: 20% each
Collision avoidance: 20%
Bonus 1 only: 10% extra
Bonus 1 + Bonus 2A: 20% extra
Bonus 1 + Bonus 2B: 20% extra
                   

Who graded your assignment based on your LAST name:

Singaravelavan Rajesh   : A  - Ch
Andre Navid Assadi      : Co - I
Kyle Nagao Oda          : J  - M
Mark Allamanno          : N  - Sh
Michelle Kwong          : Si - Z

Submission:

Submission is now split into 2 parts:

Last modified Thursday, 07-May-2020 11:23:17 PDT.