From a159a9f6376a7d7246f3c22c7e85873f53101501 Mon Sep 17 00:00:00 2001 From: mamushi641 <87245618+mamushi641@users.noreply.github.com> Date: Sat, 7 Aug 2021 16:05:42 +0800 Subject: [PATCH] Update simulation.py Apply Adapter design pattern to respond to possible scaling requirements that may arise later. --- simulation.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/simulation.py b/simulation.py index 9f6055f..c39e5e3 100644 --- a/simulation.py +++ b/simulation.py @@ -168,7 +168,7 @@ def callback(self): self.population[0][10] = 1 - def run(self): + def run(self, simulation_ad): '''run simulation''' i = 0 @@ -200,6 +200,8 @@ def run(self): 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])) + + simulation_ad.runad() def plot_sir(self, size=(6,3), include_fatalities=False, @@ -207,6 +209,17 @@ def plot_sir(self, size=(6,3), include_fatalities=False, plot_sir(self.Config, self.pop_tracker, size, include_fatalities, title) +class simulation_(): + def __init__(self): + pass + def run_(self): + pass + +class adapter: + def __init__(self): + self.simulation_ = simulation_() + def runad(self): + self.simulation_.run_() if __name__ == '__main__': @@ -239,4 +252,5 @@ def plot_sir(self, size=(6,3), include_fatalities=False, #sim.population_init() #reinitialize population to enforce new roaming bounds #run, hold CTRL+C in terminal to end scenario early - sim.run() + adapter = adapter() + sim.run(adapter)