Skip to content

Commit b7df057

Browse files
committed
feat(model): add warm-up logging + seperate reset_results() so can do a fix for when data_collection_period is 0
1 parent 4038ad8 commit b7df057

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

simulation/model.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ def interval_audit(self, interval):
344344
# Trigger next audit after desired interval has passed
345345
yield self.env.timeout(interval)
346346

347+
def reset_results(self):
348+
"""
349+
Resets results collection variables to their initial values. Used by
350+
warm_up(), and for correction to results in run().
351+
"""
352+
self.patients = []
353+
self.audit_list = []
354+
347355
def warm_up(self):
348356
"""
349357
If there is a warm-up period, then reset all results collection
@@ -353,8 +361,15 @@ def warm_up(self):
353361
# Delay process until warm-up period has completed
354362
yield self.env.timeout(self.param.warm_up_period)
355363
# Reset results variables
356-
self.patients = []
357-
self.audit_list = []
364+
self.reset_results()
365+
# Log that warm-up period has ended
366+
if self.param.warm_up_period > 0:
367+
self.param.logger.log(sim_time=self.env.now,
368+
msg='─' * 10)
369+
self.param.logger.log(sim_time=self.env.now,
370+
msg='Warm up complete.')
371+
self.param.logger.log(sim_time=self.env.now,
372+
msg='─' * 10)
358373

359374
def run(self):
360375
"""
@@ -405,3 +420,9 @@ def run(self):
405420

406421
# Run the simulation
407422
self.env.run(until=run_length)
423+
424+
# Error handling - if there was no data collection period, the
425+
# simulation ends before it has a chance to reset the results,
426+
# so we do so manually
427+
if self.param.data_collection_period == 0:
428+
self.reset_results()

0 commit comments

Comments
 (0)