-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.py
114 lines (96 loc) · 4.88 KB
/
simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import random, sys
# random.seed(42)
from person import Person
from logger import Logger
from virus import Virus
class Simulation(object):
def __init__(self, virus, pop_size, vacc_percentage, initial_infected=1):
# TODO: Create a Logger object and bind it to self.logger.
# Remember to call the appropriate logger method in the corresponding parts of the simulation.
# TODO: Store the virus in an attribute
# TODO: Store pop_size in an attribute
# TODO: Store the vacc_percentage in a variable
# TODO: Store initial_infected in a variable
# You need to store a list of people (Person instances)
# Some of these people will be infected some will not.
# Use the _create_population() method to create the list and
# return it storing it in an attribute here.
# TODO: Call self._create_population() and pass in the correct parameters.
pass
def _create_population(self):
# TODO: Create a list of people (Person instances). This list
# should have a total number of people equal to the pop_size.
# Some of these people will be uninfected and some will be infected.
# The number of infected people should be equal to the the initial_infected
# TODO: Return the list of people
pass
def _simulation_should_continue(self):
# This method will return a booleanb indicating if the simulation
# should continue.
# The simulation should not continue if all of the people are dead,
# or if all of the living people have been vaccinated.
# TODO: Loop over the list of people in the population. Return True
# if the simulation should continue or False if not.
pass
def run(self):
# This method starts the simulation. It should track the number of
# steps the simulation has run and check if the simulation should
# continue at the end of each step.
time_step_counter = 0
should_continue = True
while should_continue:
# TODO: Increment the time_step_counter
# TODO: for every iteration of this loop, call self.time_step()
# Call the _simulation_should_continue method to determine if
# the simulation should continue
should_continue = self._simulation_should_continue()
pass
# TODO: Write meta data to the logger. This should be starting
# statistics for the simulation. It should include the initial
# population size and the virus.
# TODO: When the simulation completes you should conclude this with
# the logger. Send the final data to the logger.
def time_step(self):
# This method will simulate interactions between people, calulate
# new infections, and determine if vaccinations and fatalities from infections
# The goal here is have each infected person interact with a number of other
# people in the population
# TODO: Loop over your population
# For each person if that person is infected
# have that person interact with 100 other living people
# Run interactions by calling the interaction method below. That method
# takes the infected person and a random person
pass
def interaction(self, infected_person, random_person):
# TODO: Finish this method.
# The possible cases you'll need to cover are listed below:
# random_person is vaccinated:
# nothing happens to random person.
# random_person is already infected:
# nothing happens to random person.
# random_person is healthy, but unvaccinated:
# generate a random number between 0.0 and 1.0. If that number is smaller
# than repro_rate, add that person to the newly infected array
# Simulation object's newly_infected array, so that their infected
# attribute can be changed to True at the end of the time step.
# TODO: Call logger method during this method.
pass
def _infect_newly_infected(self):
# TODO: Call this method at the end of every time step and infect each Person.
# TODO: Once you have iterated through the entire list of self.newly_infected, remember
# to reset self.newly_infected back to an empty list.
pass
if __name__ == "__main__":
# Test your simulation here
virus_name = "Sniffles"
repro_num = 0.5
mortality_rate = 0.12
virus = Virus(virus_name, repro_num, mortality_rate)
# Set some values used by the simulation
pop_size = 1000
vacc_percentage = 0.1
initial_infected = 10
# Make a new instance of the imulation
virus = Virus(virus, pop_size, vacc_percentage, initial_infected)
sim = Simulation(pop_size, vacc_percentage, initial_infected, virus)
# sim.run()