def run_the_app(): # Draw the UI elements to search for objects (pedestrians, cars, etc.) gsize, s1, s2, s3, i1, i2, i3, r1, r2, r3, run = frame_selector_ui() progress_flu_rule = DiscreteInvMarkovChain('flu-status', { 's': [s1, s2, s3], 'i': [i1, i2, i3], 'r': [r1, r2, r3] }) # s - susceptible # i - infectious # r - recovered sites = { 'home': Site('h'), 'work': Site('w') } probe_grp_size_flu = GroupSizeProbe.by_attr('flu', 'flu-status', progress_flu_rule.get_states(), msg_mode=ProbeMsgMode.DISP, memo='Mass distribution across flu status') probe_grp_size_site = GroupSizeProbe.by_rel('site', Site.AT, sites.values(), msg_mode=ProbeMsgMode.DISP, memo='Mass distribution across sites') data = "" s = Simulation() s.add_rule(progress_flu_rule) s.add_probe(probe_grp_size_flu) s.add_group(Group('g0', gsize, { 'flu-status': 's' })) sys.stdout = open('out.dat', 'w') s.run(int(run)) sys.stdout.close() with open('out.dat') as file: data = file.readlines() for line in data: st.write(line)
def simple(self): progress_flu_rule = DiscreteInvMarkovChain('flu-status', { 's': [0.95, 0.05, 0.00], 'i': [0.00, 0.50, 0.50], 'r': [0.10, 0.00, 0.90] }) # s - susceptible # i - infectious # r - recovered sites = { 'home': Site('h'), 'work': Site('w') } probe_grp_size_flu = GroupSizeProbe.by_attr('flu', 'flu-status', progress_flu_rule.get_states(), msg_mode=ProbeMsgMode.DISP, memo='Mass distribution across flu status') probe_grp_size_site = GroupSizeProbe.by_rel('site', Site.AT, sites.values(), msg_mode=ProbeMsgMode.DISP, memo='Mass distribution across sites') # ---------------------------------------------------------------------------------------------------------------------- # (1) Simulations testing the basic operations on groups and rules: # (1.1) A single-group, single-rule (1g.1r) simulation: s = Simulation() s.add_rule(progress_flu_rule) s.add_probe(probe_grp_size_flu) s.add_group(Group('g0', 1000, { 'flu-status': 's' })) sys.stdout = open('out.dat', 'w') s.run(24) sys.stdout.close() with open('out.dat') as file: self.data = file.readlines() self.data = str(self.data) apple = self.data.replace('\\n', '<br>') # print(apple) return apple
probe_grp_size_site = GroupSizeProbe.by_rel( 'site', Site.AT, sites.values(), msg_mode=ProbeMsgMode.DISP, memo='Mass distribution across sites') # ---------------------------------------------------------------------------------------------------------------------- # (1) Simulations testing the basic operations on groups and rules: # (1.1) A single-group, single-rule (1g.1r) simulation: s = Simulation() s.add_rule(progress_flu_rule) s.add_probe(probe_grp_size_flu) s.add_group(Group('g0', 1000, {'flu-status': 's'})) s.run(24) # (1.2) A single-group, two-rule (1g.2r) simulation: # s = Simulation() # s.add_rule(progress_flu_rule) # s.add_rule(GoToRule(TimeInt(10,16), 0.4, 'home', 'work')) # s.add_probe(probe_grp_size_flu) # s.add_group(Group('g0', 1000, { 'flu-status': 's' }, { Site.AT: sites['home'], 'home': sites['home'], 'work': sites['work'] })) # s.run(24) # (1.3) As above (1g.2r), but with reversed rule order (which should not, and does not, change the results): # s = Simulation() # s.add_rule(GoToRule(TimeInt(10,16), 0.4, 'home', 'work')) # s.add_rule(progress_flu_rule) # s.add_probe(probe_grp_size_flu) # s.add_group(Group('g0', 1000, { 'flu-status': 's' }, { Site.AT: sites['home'], 'home': sites['home'], 'work': sites['work'] }))
# (1) Simulations testing the basic operations on groups and rules: sites = {'home': Site('h'), 'work': Site('w')} probe_grp_size_flu = GroupSizeProbe.by_attr( 'flu', 'flu-stage', AttrFluStage, memo='Mass distribution across flu stages') # (1.1) A single-group, single-rule (1g.1r) simulation: s = Simulation(6, 1, 16, rand_seed=rand_seed) s.create_group(1000, {'flu-stage': AttrFluStage.NO}) s.add_rule(ProgressFluRule()) s.add_probe(probe_grp_size_flu) s.run() # (1.2) A single-group, two-rule (1g.2r) simulation: # s = Simulation(6,1,16, rand_seed=rand_seed) # s.create_group(1000, { 'flu-stage': AttrFluStage.NO }, { Site.AT: sites['home'], 'home': sites['home'], 'work': sites['work'] }) # s.add_rule(ProgressFluRule()) # s.add_rule(GotoRule(TimeInt(10,16), 0.4, 'home', 'work')) # s.add_probe(probe_grp_size_flu) # s.run() # (1.3) As above (1g.2r), but with reversed rule order (which should not, and does not, change the results): # s = Simulation(6,1,16, rand_seed=rand_seed) # s.create_group(1000, { 'flu-stage': AttrFluStage.NO }, { Site.AT: sites['home'], 'home': sites['home'], 'work': sites['work'] }) # s.add_rule(GotoRule(TimeInt(10,16), 0.4, 'home', 'work')) # s.add_rule(ProgressFluRule()) # s.add_probe(probe_grp_size_flu)