Added optional graphical simulation
This commit is contained in:
parent
a795535a64
commit
81effb7b6c
1 changed files with 13 additions and 5 deletions
14
malaria.py
14
malaria.py
|
@ -9,12 +9,14 @@ 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**-3,
|
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,
|
||||||
|
graphical=True):
|
||||||
|
|
||||||
plt.ion()
|
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
|
||||||
|
# Determines if the simulation should be graphical
|
||||||
|
self.graphical = graphical
|
||||||
# The percentage of tiles that start as humans
|
# The percentage of tiles that start as humans
|
||||||
self.humandens = humandens
|
self.humandens = humandens
|
||||||
# The percentage of tiles that contain mosquitos
|
# The percentage of tiles that contain mosquitos
|
||||||
|
@ -42,9 +44,12 @@ class Model:
|
||||||
|
|
||||||
self.grid = self.gen_humans()
|
self.grid = self.gen_humans()
|
||||||
self.mosquitos = self.gen_mosquitos()
|
self.mosquitos = self.gen_mosquitos()
|
||||||
|
|
||||||
|
if self.graphical:
|
||||||
self.init_draw()
|
self.init_draw()
|
||||||
|
|
||||||
def init_draw(self):
|
def init_draw(self):
|
||||||
|
plt.ion()
|
||||||
self.colors = matplotlib.colors.ListedColormap(
|
self.colors = matplotlib.colors.ListedColormap(
|
||||||
["black", "green", "red", "yellow"])
|
["black", "green", "red", "yellow"])
|
||||||
bounds = [Human.DEAD, Human.HEALTHY, Human.INFECTED, Human.IMMUNE]
|
bounds = [Human.DEAD, Human.HEALTHY, Human.INFECTED, Human.IMMUNE]
|
||||||
|
@ -162,7 +167,10 @@ class Model:
|
||||||
"""
|
"""
|
||||||
for t in range(self.time_steps):
|
for t in range(self.time_steps):
|
||||||
self.step()
|
self.step()
|
||||||
|
if self.graphical:
|
||||||
self.draw(t)
|
self.draw(t)
|
||||||
|
else:
|
||||||
|
print("Simulating timestep: {}".format(t), end='\r')
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
"""
|
"""
|
||||||
|
@ -214,6 +222,6 @@ class Human(IntEnum):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
model = Model()
|
model = Model(graphical=False)
|
||||||
model.run()
|
model.run()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue