def pandemic(): env = World(50, 10, 0.3) max_pop = len(env.list_available_tiles()) pop = int(max_pop * 0.7) deathProbability = 0.5 recoverProbability = 0.3 infectedProbability = 0.8 plague = Pandemic(1000, pop, infectedProbability, recoverProbability, deathProbability, env, 1) plague.show(True)
def move(): env = World(20, 20, 0.2) max_pop = len(env.list_available_tiles()) pop = int(max_pop * 0.3) deathProbability = 0.04 recoverProbability = 0.3 infectedProbability = 0.7 plague = Pandemic(1000, pop, infectedProbability, recoverProbability, deathProbability, env, 1) plague.world.display()
def stack_chart(): env = World(50, 10, 0.25) max_pop = len(env.list_available_tiles()) pop = int(max_pop*0.7) deathProbability = 0.04 recoverProbability = 0.2 infectedProbability = 0.75 epochs = 1000 plague = Pandemic(epochs, pop, infectedProbability, recoverProbability, deathProbability, env, 1, 1) plague.spread(True) x = range(1, plague.hardstop+2) y = [plague.healthy, plague.cured, plague.infected, plague.dead] pal = ["#2ecc71", "#3498db", "#e74c3c", "#9b59b6"] try: system('clear') for i in range(3): print("Simulation starting in " + str(3-i) + "...") time.sleep(1) system('clear') except KeyboardInterrupt: pass for i in range(plague.hardstop): try: y = [plague.healthy[:i], plague.cured[:i], plague.infected[:i], plague.dead[:i]] plt.stackplot(x[:i], y, labels=['Unaffected', 'Cured', 'Infected', 'Dead'], colors=pal, alpha=0.4) plague.displayWorldHistory(i) if i == 0: plt.legend(loc='upper left') plt.pause(0.1) except KeyboardInterrupt: print("Exiting cleanly...") sys.exit() while(True): try: plt.show() except KeyboardInterrupt: print("Exiting cleanly...") sys.exit()
def main(): env = World(10, 10, 0.2) env.display()
def test_float_initial_cases(): env = World(50, 10, 0.3) corona = Pandemic(1000, -3, 0, 0, 0, env, -2.9, 0.5) assert (isinstance(corona.n_infected, int) == True)
def test_float_population(): env = World(50, 10, 0.3) corona = Pandemic(1000, 99.44, 0, 0, 0, env, 1, 1) assert (isinstance(corona.population, int) == True)
def test_outofbounds_spreadrange(): env = World(50, 10, 0.3) corona = Pandemic(1000, -3, 0, 0, 0, env, -2, 500) assert (corona.spreadRange == 0 or corona.spreadRange == 1)
def test_float_spreadrange(): env = World(50, 10, 0.3) corona = Pandemic(1000, -3, 0, 0, 0, env, -2, 0.5) assert (corona.spreadRange == 0 or corona.spreadRange == 1)
def test_negative_spreadrange(): env = World(50, 10, 0.3) corona = Pandemic(1000, -3, 0, 0, 0, env, -2, -2) assert (corona.spreadRange == 0 or corona.spreadRange == 1)
def test_negative_initial_cases(): env = World(50, 10, 0.3) corona = Pandemic(1000, -3, 0, 0, 0, env, -2) assert (corona.n_infected >= 0)
def test_population_overflow(): env = World(50, 10, 0.3) corona = Pandemic(1000, 999999, 0.1, 0.1, 0.1, env) assert (corona.population == len(env.initial_available))
def test_negative_population(): env = World(50, 10, 0.3) corona = Pandemic(1000, -3, 0.1, 0.1, 0.1, env) assert (corona.population > 0)
# -*- coding: utf-8 -*- import sys from os import path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from lib.env import World from lib.pandemic import Pandemic import random a_env = World(50, 10, 0.3) max_pop = len(a_env.list_available_tiles()) pop = int(max_pop * 0.7) deathProbability = 0.5 recoverProbability = 0.3 infectedProbability = 0.8 plague = Pandemic(1000, pop, infectedProbability, recoverProbability, deathProbability, a_env, 1) plague.spread() def test_population_consistancy(): if plague.hardstop != 0: loop = plague.hardstop else: loop = plague.epochs for i in range(loop): assumed_pop = plague.dead[i] + plague.cured[i] + plague.healthy[ i] + plague.infected[i]