def run(self): '''run simulation''' i = 0 while i < self.Config.simulation_steps: try: self.tstep() except KeyboardInterrupt: print('\nCTRL-C caught, exiting') sys.exit(1) #check whether to end if no infecious persons remain. #check if self.frame is above some threshold to prevent early breaking when simulation #starts initially with no infections. if self.Config.endif_no_infections and self.frame >= 500: if len(self.population[(self.population[:,6] == 1) | (self.population[:,6] == 4)]) == 0: i = self.Config.simulation_steps if self.Config.save_data: save_data(self.population, self.pop_tracker) #report outcomes print('\n-----stopping-----\n') print('total timesteps taken: %i' %self.frame) print('total dead: %i' %len(self.population[self.population[:,6] == 3])) print('total recovered: %i' %len(self.population[self.population[:,6] == 2])) print('total infected: %i' %len(self.population[self.population[:,6] == 1])) print('total infectious: %i' %len(self.population[(self.population[:,6] == 1) | (self.population[:,6] == 4)])) print('total unaffected: %i' %len(self.population[self.population[:,6] == 0]))
def run(self): '''run simulation''' if self.Config.visualise: self.fig, self.spec, self.ax1, self.ax2, self.tight_bbox = build_fig( self.Config) i = 0 while i < self.Config.simulation_steps: try: self.tstep() except KeyboardInterrupt: print('\nCTRL-C caught, exiting') sys.exit(1) #check whether to end if no infectious persons remain. #check if self.frame is above some threshold to prevent early breaking when simulation #starts initially with no infections. if self.Config.endif_no_infections and self.frame >= 300: if len(self.population[(self.population[:, 6] == 1) | (self.population[:, 6] == 4)]) == 0: i = self.Config.simulation_steps else: i += 1 if self.Config.plot_last_tstep: self.fig_sir, self.spec_sir, self.ax1_sir = build_fig_SIRonly( self.Config) draw_SIRonly(self.Config, self.population, self.pop_tracker, self.frame, self.fig_sir, self.spec_sir, self.ax1_sir) if self.Config.save_data: save_data(self.population, self.pop_tracker) #report outcomes if self.Config.verbose: print('\n-----stopping-----\n') print('total timesteps taken: %i' % self.frame) print('total dead: %i' % len(self.population[self.population[:, 6] == 3])) print('total recovered: %i' % len(self.population[self.population[:, 6] == 2])) print('total infected: %i' % len(self.population[self.population[:, 6] == 1])) print('total infectious: %i' % len(self.population[(self.population[:, 6] == 1) | (self.population[:, 6] == 4)])) print('total unaffected: %i' % len(self.population[self.population[:, 6] == 0])) print('mean distance travelled: %f' % np.mean(self.pop_tracker.distance_travelled))
infection_chance, speed, recovery_duration, mortality_chance, xbounds, ybounds, x_plot, y_plot, wander_range, risk_age, critical_age, critical_mortality_chance, risk_increase, no_treatment_factor, treatment_factor, healthcare_capacity, age_dependent_risk, treatment_dependent_risk, visualise, verbose, self_isolate, self_isolate_proportion, isolation_bounds, traveling_infects, lockdown, lockdown_percentage, lockdown_vector, plot_style) if len(population[population[:, 6] == 1]) == 0 and i > 100: print('\n-----stopping-----\n') print('total dead: %i' % len(population[population[:, 6] == 3])) print('total immune: %i' % len(population[population[:, 6] == 2])) if save_population: save_data(population, infected_plot, fatalities_plot) i = simulation_steps + 1 sys.stdout.write('\r') sys.stdout.write( '%i: healthy: %i, infected: %i, immune: %i, in treatment: %i, \ dead: %i, of total: %i' % (i, len(population[population[:, 6] == 0]), len(population[population[:, 6] == 1]), len(population[population[:, 6] == 2]), len(population[population[:, 10] == 1]), len(population[population[:, 6] == 3]), pop_size)) i += 1 print('\n-----stopping after all sick recovered or died-----\n') print('total dead: %i' % len(population[population[:, 6] == 3]))