def __init__(self,
                 t=TimeInt(0, 23),
                 p_think=0.5,
                 p_eat=0.5,
                 is_verbose=False,
                 memo=None):
        super().__init__('think-and-eat', t, memo)

        self.p_think = p_think
        self.p_eat = p_eat
        self.is_verbose = is_verbose
Exemple #2
0
                  0).  # confirm that only one pruned group exists
 run()  # confirm that the simulation runs
 )
print()

# ----------------------------------------------------------------------------------------------------------------------
# (3) Improper simulations (that will not run):

# (3.1) Problem: Attempting to add a rule after having added a group:
print('(3.1)')
try:
    (Simulation(TimeHour(6), 16).add_rule(
        ProgressFluRule()).add_probe(probe_grp_size_flu).new_group(
            '0',
            1000).set_attr('flu-stage', AttrFluStage.NO).commit().add_rule(
                GoToRule(TimeInt(10, 16), 0.4, 'home', 'work')))
except SimulationConstructionError as e:
    print(e)
print()

# (3.2) Problem: Attempting to add a group with no rules present:
print('(3.2)')
try:
    (Simulation(TimeHour(6), 16).new_group('0', 1000).set_attr(
        'flu-stage', AttrFluStage.NO).commit().add_rule(
            ProgressFluRule()).add_probe(probe_grp_size_flu))
except SimulationConstructionError as e:
    print(e)
print()

# (3.3) Problem: A group has superfluous attributes and relations:
Exemple #3
0
    def __init__(self, t=TimeInt(8,20), p_infection_min=0.01, p_infection_max=0.95, memo=None):  # 8am - 8pm
        super().__init__('progress-flu', t, memo)

        self.p_infection_min = p_infection_min
        self.p_infection_max = p_infection_max
Exemple #4
0
 def __init__(self, t=TimeInt(8,20), memo=None):
     super().__init__('progress-flu', t, memo)
(Simulation(6,1,24, rand_seed=rand_seed).
    new_group('g0', 1000).
        set_rel(Site.AT, sites['home']).
        set_rel('home',  sites['home']).
        set_rel('work',  sites['work-a']).
        set_rel('store', sites['store-a']).
        commit().
    new_group('g1', 1000).
        set_rel(Site.AT, sites['home']).
        set_rel('home',  sites['home']).
        set_rel('work',  sites['work-b']).
        set_rel('store', sites['store-b']).
        commit().
    new_group('g2', 100).
        set_rel(Site.AT, sites['home']).
        set_rel('home',  sites['home']).
        set_rel('work',  sites['work-c']).
        commit().
    add_rule(GotoRule(TimeInt( 8,12), 0.4, 'home',  'work',  'Some agents leave home to go to work')).
    add_rule(GotoRule(TimeInt(16,20), 0.4, 'work',  'home',  'Some agents return home from work')).
    add_rule(GotoRule(TimeInt(16,21), 0.2, 'home',  'store', 'Some agents go to a store after getting back home')).
    add_rule(GotoRule(TimeInt(17,23), 0.3, 'store', 'home',  'Some shopping agents return home from a store')).
    add_rule(GotoRule(TimePoint(24),  1.0, 'store', 'home',  'All shopping agents return home after stores close')).
    add_rule(GotoRule(TimePoint( 2),  1.0, None,    'home',  'All still-working agents return home')).
    add_probe(probe_grp_size_site).
    summary((True, True, True, True, True), (0,1)).
    run().
    summary((False, True, False, False, False), (1,1)).
    run(4)
)
Exemple #6
0
 def __init__(self, t=TimeInt(8, 16), memo=None):
     super().__init__('attend-school', t, memo)
Exemple #7
0
        print(self._dump(tree))

    @staticmethod
    def get_str(node):
        return list(ast.iter_fields(node))[0][1]


from pram.rule import GotoRule, TimeInt
from sim.rules import AttendSchoolRule, ProgressFluRule, ProgressAndTransmitFluRule

ra = RuleAnalyzer()

# ra.analyze(ProgressFluRule())
# ra.analyze(R())

ra.analyze(GotoRule(TimeInt(8, 12), 0.4, 'home', 'work'))

# ra.analyze(ProcessRule(AttendSchoolRule())
# ra.analyze(ProcessRule(ProgressFluRule())
# ra.analyze(ProcessRule(ProgressAndTransmitFluRule())

# ra.dump(ProgressFluRule())
# ra.dump(R())

print('----')
print(f'attr    : {ra.attr}')
print(f'rel     : {ra.rel}')
print(f'known   : {ra.cnt_known}')
print(f'unknown : {ra.cnt_unknown}')

# ----
Exemple #8
0
 def __init__(self, t=TimeInt(0, 12), memo=None):
     super().__init__('snake-eats-mice', t, memo)
     self.T_UNIT_MS = Time.MS.M
Exemple #9
0
 def __init__(self, t=TimeInt(0, 12), memo=None):
     super().__init__('mice-birth', t, memo)
     self.T_UNIT_MS = Time.MS.M
Exemple #10
0
 def __init__(self, t=TimeInt(0, 12), memo=None):
     super().__init__('hunter-kills-snakes', t, memo)
     self.T_UNIT_MS = Time.MS.M
Exemple #11
0
    s: Site(s)
    for s in ['home', 'work-a', 'work-b', 'work-c', 'store-a', 'store-b']
}

probe_grp_size_site = GroupSizeProbe.by_rel(
    'site',
    Site.AT,
    sites.values(),
    msg_mode=ProbeMsgMode.DISP,
    memo='Mass distribution across sites')

(Simulation().add().rule(
    GoToRule(0.4,
             'home',
             'work',
             TimeInt(8, 12),
             memo='Some agents leave home to go to work')).rule(
                 GoToRule(0.4,
                          'work',
                          'home',
                          TimeInt(16, 20),
                          memo='Some agents return home from work')).
 rule(
     GoToRule(0.2,
              'home',
              'store',
              TimeInt(16, 21),
              memo='Some agents go to a store after getting back home')).rule(
                  GoToRule(
                      0.3,
                      'store',