def run(from_script=False): """ This is the main function that actually runs the demo, as one might expect. It does the folllowing: - Register callbacks - Create human population - Foreach timestep: - Do shedding loop for each individual - Calculate adjusted force of infection - Do vital dynamics & exposure update for each individual - Distribute interventions - "Migration" - Plot simple reports summarizing results """ global human_pop # make sure Python knows to use module-level variable human_pop del human_pop[:] setup_callbacks() nd.populate_from_files() if len(human_pop) == 0: print( "Failed to create any people in populate_from_files. This isn't going to work!" ) sys.exit(0) graveyard = [] global timestep global contagion_buckets #global contagion_bucket_homog for t in range(0, sim_duration): # for one year timestep = t do_shedding_update(human_pop) #contagion_bucket_homog /= len(human_pop) do_vitaldynamics_update(human_pop, graveyard) distribute_interventions(t) #report_channels[ "Infected" ].append( prevalence[-1] ) print( "At end of timestep {0} num_infected = {1} stat_pop = {2}, disease deaths = {3}." .format(t, prevalence[-1], len(human_pop), len(graveyard))) contagion_buckets = [0, 0] #contagion_bucket_homog = 0 # Sim done: Report. plt.plot(susceptible, color='green', label='S') plt.plot(exposeds, color='purple', label='E') plt.plot(prevalence, color='orange', label='I') plt.plot(recovered, color='blue', label='R') plt.plot(disdeaths, color='red', label='D') #plt.title( "Infections" ) #plt.plot( report_channels[ "Infected" ], color='orange' ) plt.xlabel("time") #plt.ylabel( "infected individuals" ) plt.legend() plt.show() if from_script: print("NURSERY\n" + json.dumps(nursery, indent=4)) print("GRAVEYARD\n" + json.dumps(graveyard, indent=4)) return graveyard
def run(from_script=False): """ This is the main function that actually runs the demo, as one might expect. It does the folllowing: - Register callbacks - Create human population - Foreach timestep: - Do shedding loop for each individual - Calculate adjusted force of infection - Do vital dynamics & exposure update for each individual - Distribute interventions - "Migration" - Plot simple reports summarizing results """ global human_pop # make sure Python knows to use module-level variable human_pop del human_pop[:] setup_callbacks() nd.populate_from_files() if len(human_pop) == 0: print( "Failed to create any people in populate_from_files. This isn't going to work!" ) sys.exit(0) graveyard = [] global timestep global contagion_buckets dis_death_cum = 0 #global contagion_bucket_homog for t in range(0, sim_duration): # for one year timestep = t stat_pop = do_shedding_update(human_pop) #contagion_bucket_homog /= len(human_pop) do_vitaldynamics_update(human_pop, graveyard, contagion_buckets) distribute_interventions(t) dis_death_cum += disdeaths[-1] print( f"At end of timestep {t} num_infected = {prevalence[-1]} stat_pop = {stat_pop}, disease deaths = {dis_death_cum}." ) contagion_buckets = [0, 0] #contagion_bucket_homog = 0 # Sim done: Report. # save prevalence with tag and timestamp tag = (sys.argv[1] + "_") if len(sys.argv) > 1 else "" # secret tag option save_output(tag) # This could get moved to core but users might want to play with it. plt.plot(susceptible, color='green', label='S') plt.plot(exposeds, color='purple', label='E') plt.plot(prevalence, color='orange', label='I') plt.plot(recovered, color='blue', label='R') plt.plot(disdeaths, color='red', label='D') plt.xlabel("time") plt.legend() plt.show() if from_script: print("NURSERY\n" + json.dumps(nursery, indent=4)) print("GRAVEYARD\n" + json.dumps(graveyard, indent=4)) return graveyard
return True else: return False def get_mcw(self): self.serialize_me() return self.individual_json["m_mc_weight"] pass if __name__ == "__main__": demo = WerewolfDemo(debug=False, enable_reporting=True) demo.debug = False demo.define_population(1000) dnd.set_callback(demo.create_person_callback) dnd.populate_from_files() if demo.debug: print("Population created\n") men = 0 women = 0 ages = [] for h in demo.humans: alex = DtkPerson(h) if alex.is_male(): men += 1 else: women += 1 pass ages.append(alex.get_age()) pass print(f'Total men: {men}\tTotal women: {women}')