From c5a3d0f96aac84067dd167c24ff7025b168df716 Mon Sep 17 00:00:00 2001 From: zhoukeyu Date: Sat, 21 Aug 2021 01:40:23 +0800 Subject: [PATCH 1/2] Switched to a new branch 'mybranch' --- python_corona_simulation | 1 + 1 file changed, 1 insertion(+) create mode 160000 python_corona_simulation diff --git a/python_corona_simulation b/python_corona_simulation new file mode 160000 index 0000000..a5dddd3 --- /dev/null +++ b/python_corona_simulation @@ -0,0 +1 @@ +Subproject commit a5dddd3e13d2bb768a9294d85ab27329be9a21dd From a1dee574fb20318e4d963af369ec498b9e9b765d Mon Sep 17 00:00:00 2001 From: zhoukeyu Date: Sat, 21 Aug 2021 02:17:40 +0800 Subject: [PATCH 2/2] python_corona_simulation --- Command.py | 28 ++++++++++++++++++++++++++++ Iterator.py | 22 ++++++++++++++++++++++ demo_COVID.py | 4 ++-- population.py | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Command.py create mode 100644 Iterator.py diff --git a/Command.py b/Command.py new file mode 100644 index 0000000..b77efa8 --- /dev/null +++ b/Command.py @@ -0,0 +1,28 @@ +from abc import abstractmethod +import simulation +import utils +import visualiser +class command(): + @abstractmethod + def __init__(self,name): + self.name=name + + @abstractmethod + def excute(self): + pass + + +class simulateCommand(command): + def excute(self): + simulation.run() + +class savefileCutCommand(command): + def excute(self,folder): + utils.check_folder(folder) + + + +class pltCommand(command): + def excute(self): + visualiser.plot_sir() + diff --git a/Iterator.py b/Iterator.py new file mode 100644 index 0000000..a7007e9 --- /dev/null +++ b/Iterator.py @@ -0,0 +1,22 @@ +from abc import abstractmethod + + +class iterator(): + @abstractmethod + def getNext(self): + pass + + @abstractmethod + def hasMore(self): + pass + +class populationIterator(iterator): + def __init__(self,tracker): + self.tracker=tracker + self.currentposition=0 + def getNext(self): + if(self.hasMore()): + self.currentposition+=1 + return self.tracker[self.currentposition] + def hasMore(self): + return self.currentposition < len(self.tracker) \ No newline at end of file diff --git a/demo_COVID.py b/demo_COVID.py index 2443544..2b7b15b 100644 --- a/demo_COVID.py +++ b/demo_COVID.py @@ -1,6 +1,6 @@ import os import sys - +import command import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation @@ -433,6 +433,6 @@ def update(frame, population, destinations, pop_size, infection_range=0.01, treatment_factor, healthcare_capacity, age_dependent_risk, treatment_dependent_risk, visualise, verbose,) - + command.excute(plt) animation = FuncAnimation(fig, update, fargs = fargs, frames = simulation_steps, interval = 33) plt.show() \ No newline at end of file diff --git a/population.py b/population.py index 2879a8b..8e7a86b 100644 --- a/population.py +++ b/population.py @@ -10,7 +10,7 @@ from motion import get_motion_parameters from utils import check_folder - +import iterator def initialize_population(Config, mean_age=45, max_age=105, xbounds=[0, 1], ybounds=[0, 1]): '''initialized the population for the simulation