people now die randomly
This commit is contained in:
parent
8a7eb62af4
commit
89e9b4f2f8
2 changed files with 21 additions and 10 deletions
BIN
.vscode/.ropeproject/objectdb
vendored
Normal file
BIN
.vscode/.ropeproject/objectdb
vendored
Normal file
Binary file not shown.
31
malaria.py
31
malaria.py
|
@ -8,7 +8,7 @@ from enum import IntEnum
|
||||||
class Model:
|
class Model:
|
||||||
def __init__(self, width=32, height=32, humandens=0.15, mosquitodens=0.10,
|
def __init__(self, width=32, height=32, humandens=0.15, mosquitodens=0.10,
|
||||||
immunepct=0.1, mosqinfpct=0.1, hm_infpct=0.5, mh_infpct=0.5,
|
immunepct=0.1, mosqinfpct=0.1, hm_infpct=0.5, mh_infpct=0.5,
|
||||||
hinfdiepct=0.01, mhungrypct=0.1, humandiepct=10**-6,
|
hinfdiepct=0.01, mhungrypct=0.1, humandiepct=10**-3,
|
||||||
mosqdiepct=10**-3, mosqnetdens=0.05, time_steps=2000):
|
mosqdiepct=10**-3, mosqnetdens=0.05, time_steps=2000):
|
||||||
|
|
||||||
plt.ion()
|
plt.ion()
|
||||||
|
@ -40,7 +40,7 @@ class Model:
|
||||||
# The number of timesteps to run te simulation for
|
# The number of timesteps to run te simulation for
|
||||||
self.time_steps = time_steps
|
self.time_steps = time_steps
|
||||||
|
|
||||||
self.humans = self.gen_humans()
|
self.grid = self.gen_humans()
|
||||||
self.mosquitos = self.gen_mosquitos()
|
self.mosquitos = self.gen_mosquitos()
|
||||||
self.init_draw()
|
self.init_draw()
|
||||||
|
|
||||||
|
@ -52,31 +52,41 @@ class Model:
|
||||||
|
|
||||||
def recycle_human(self):
|
def recycle_human(self):
|
||||||
# Get all living humans
|
# Get all living humans
|
||||||
humans = np.transpose(np.where(self.humans != Human.DEAD))
|
humans = np.transpose(np.where(self.grid != Human.DEAD))
|
||||||
|
|
||||||
# Get a mask of humans to kill
|
# Get a mask of humans to kill
|
||||||
deaths = np.random.rand(len(humans)) < self.humandiepct
|
deaths = np.random.rand(len(humans)) < self.humandiepct
|
||||||
|
|
||||||
# Kill them.
|
# Kill them.
|
||||||
self.humans[humans[deaths][:, 0], humans[deaths][:, 1]] = Human.DEAD
|
self.grid[humans[deaths][:, 0], humans[deaths][:, 1]] = Human.DEAD
|
||||||
|
|
||||||
|
# get num humans after killing
|
||||||
|
humans_survive = len(np.transpose(np.where(self.grid != Human.DEAD)))
|
||||||
|
|
||||||
|
death_count = len(humans) - humans_survive
|
||||||
|
|
||||||
|
|
||||||
# Pick a random, unpopulated spot
|
# Pick a random, unpopulated spot
|
||||||
x, y = random.choice(np.transpose(np.where(self.humans == Human.DEAD)),
|
births = np.array(random.sample(list(np.transpose(np.where(self.grid == Human.DEAD))),
|
||||||
size=np.count_nonzero(deaths))
|
death_count))
|
||||||
|
|
||||||
|
# Deliver the newborns
|
||||||
|
for birth in births:
|
||||||
|
self.grid[birth[0]][birth[1]] = np.random.choice([Human.HEALTHY, Human.IMMUNE],
|
||||||
|
p=[1-self.immunepct, self.immunepct])
|
||||||
|
|
||||||
def do_malaria(self):
|
def do_malaria(self):
|
||||||
"""
|
"""
|
||||||
This function determines who of the infected dies from their illness
|
This function determines who of the infected dies from their illness
|
||||||
"""
|
"""
|
||||||
# Get all infected humans
|
# Get all infected humans
|
||||||
infected = np.transpose(np.where(self.humans == Human.INFECTED))
|
infected = np.transpose(np.where(self.grid == Human.INFECTED))
|
||||||
|
|
||||||
# Decide which infected people die
|
# Decide which infected people die
|
||||||
deaths = np.random.rand(len(infected)) < self.hinfdiepct
|
deaths = np.random.rand(len(infected)) < self.hinfdiepct
|
||||||
|
|
||||||
# Now let's kill them
|
# Now let's kill them
|
||||||
self.humans[infected[deaths][:, 0], infected[deaths][:, 1]] = Human.DEAD
|
self.grid[infected[deaths][:, 0], infected[deaths][:, 1]] = Human.DEAD
|
||||||
|
|
||||||
def gen_humans(self):
|
def gen_humans(self):
|
||||||
# Calculate the probabilities
|
# Calculate the probabilities
|
||||||
|
@ -98,12 +108,13 @@ class Model:
|
||||||
self.draw(t)
|
self.draw(t)
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
self.do_malaria()
|
# self.do_malaria()
|
||||||
|
self.recycle_human()
|
||||||
|
|
||||||
def draw(self, t):
|
def draw(self, t):
|
||||||
# this function draws the humans
|
# this function draws the humans
|
||||||
plt.title("t={}".format(t))
|
plt.title("t={}".format(t))
|
||||||
plt.imshow(self.humans, cmap=self.colors, norm=self.norm)
|
plt.imshow(self.grid, cmap=self.colors, norm=self.norm)
|
||||||
|
|
||||||
plt.pause(0.0001)
|
plt.pause(0.0001)
|
||||||
plt.clf()
|
plt.clf()
|
||||||
|
|
Loading…
Reference in a new issue