1414from path_planning import go_to_location , set_destination , check_at_destination ,\
1515keep_at_destination , reset_destinations
1616from population import initialize_population , initialize_destination_matrix ,\
17- set_destination_bounds , save_data , Population_trackers
17+ set_destination_bounds , save_data , save_population , Population_trackers
1818from visualiser import build_fig , draw_tstep , set_style
1919
2020#set seed for reproducibility
@@ -119,10 +119,19 @@ def tstep(self):
119119 self .pop_tracker .update_counts (self .population )
120120
121121 #visualise
122- draw_tstep (self .Config , self .population , self .pop_tracker , self .frame ,
123- self .fig , self .spec , self .ax1 , self .ax2 )
124-
125-
122+ if self .Config .visualise :
123+ draw_tstep (self .Config , self .population , self .pop_tracker , self .frame ,
124+ self .fig , self .spec , self .ax1 , self .ax2 )
125+ else :
126+ #report stuff to console
127+ sys .stdout .write ('\r ' )
128+ sys .stdout .write ('%i: healthy: %i, infected: %i, immune: %i, in treatment: %i, \
129+ dead: %i, of total: %i' % (self .frame , self .pop_tracker .susceptible [- 1 ], self .pop_tracker .infectious [- 1 ],
130+ self .pop_tracker .recovered [- 1 ], len (self .population [self .population [:,10 ] == 1 ]),
131+ self .pop_tracker .fatalities [- 1 ], self .Config .pop_size ))
132+ #save popdata if required
133+ if self .Config .save_pop and (self .frame % self .Config .save_pop_freq ) == 0 :
134+ save_population (self .population , self .frame , self .Config .save_pop_folder )
126135 #run callback
127136 self .callback ()
128137
@@ -145,18 +154,34 @@ def callback(self):
145154
146155
147156 def run (self ):
148- for t in range ( self .Config .simulation_steps ) :
157+ while self . frame < self .Config .simulation_steps :
149158 try :
150159 sim .tstep ()
151- sys .stdout .write ('\r ' )
152- sys .stdout .write ('%i / %i' % (t , self .Config .simulation_steps ))
153160 except KeyboardInterrupt :
154161 print ('\n CTRL-C caught, exiting' )
155162 sys .exit (1 )
156163
164+ #check whether to end if no infecious persons remain.
165+ #check if self.frame is above some threshold to prevent early breaking when simulation
166+ #starts initially with no infections.
167+ if self .Config .endif_no_infections and self .frame >= 500 :
168+ if len (self .population [(self .population [:,6 ] == 1 ) |
169+ (self .population [:,6 ] == 4 )]) == 0 :
170+ self .frame = self .Config .simulation_steps
171+
157172 if self .Config .save_data :
158173 save_data (self .population , self .pop_tracker )
159174
175+ #report outcomes
176+ print ('\n -----stopping-----\n ' )
177+ print ('total dead: %i' % len (self .population [self .population [:,6 ] == 3 ]))
178+ print ('total recovered: %i' % len (self .population [self .population [:,6 ] == 2 ]))
179+ print ('total infected: %i' % len (self .population [self .population [:,6 ] == 1 ]))
180+ print ('total infectious: %i' % len (self .population [(self .population [:,6 ] == 1 ) |
181+ (self .population [:,6 ] == 4 )]))
182+ print ('total unaffected: %i' % len (self .population [self .population [:,6 ] == 0 ]))
183+
184+
160185
161186if __name__ == '__main__' :
162187
@@ -175,8 +200,8 @@ def run(self):
175200 #sim.Config.colorblind_type = 'deuteranopia'
176201
177202 #set reduced interaction
178- sim .Config .set_reduced_interaction ()
179- sim .population_init ()
203+ # sim.Config.set_reduced_interaction()
204+ # sim.population_init()
180205
181206 #set lockdown scenario
182207 #sim.Config.set_lockdown(lockdown_percentage = 0.1, lockdown_compliance = 0.95)
0 commit comments