Esempio n. 1
0
def run_simu(n_people=None,
             init_percent_sick=0,
             start_time=datetime.datetime(2020, 2, 28, 0, 0),
             simulation_days=10,
             outfile=None,
             out_chunk_size=None,
             print_progress=False,
             seed=0,
             port=6688,
             n_jobs=1,
             other_monitors=[]):

    rng = np.random.RandomState(seed)
    env = Env(start_time)
    city_x_range = (0, 1000)
    city_y_range = (0, 1000)
    city = City(env, n_people, rng, city_x_range, city_y_range, start_time,
                init_percent_sick, Human)
    monitors = [
        EventMonitor(f=120, dest=outfile, chunk_size=out_chunk_size),
        SEIRMonitor(f=1440)
    ]

    # run the simulation
    if print_progress:
        monitors.append(TimeMonitor(1440))  # print every day

    if other_monitors:
        monitors += other_monitors

    for human in city.humans:
        env.process(human.run(city=city))

    for m in monitors:
        env.process(m.run(env, city=city))

    all_possible_symptoms = [
        'moderate', 'mild', 'severe', 'extremely-severe', 'fever', 'chills',
        'gastro', 'diarrhea', 'nausea_vomiting', 'fatigue', 'unusual',
        'hard_time_waking_up', 'headache', 'confused', 'lost_consciousness',
        'trouble_breathing', 'sneezing', 'cough', 'runny_nose', 'aches',
        'sore_throat', 'severe_chest_pain', 'loss_of_taste',
        'mild_trouble_breathing', 'light_trouble_breathing',
        'moderate_trouble_breathing', 'heavy_trouble_breathing'
    ]
    monitors[0].dump()
    monitors[0].join_iothread()
    env.process(
        city.run(1440, outfile, start_time, all_possible_symptoms, port,
                 n_jobs))

    env.run(until=simulation_days * 24 * 60 / TICK_MINUTE)

    return monitors, city.tracker
Esempio n. 2
0
def run_simu(n_people=None,
             init_percent_sick=0.0,
             start_time=datetime.datetime(2020, 2, 28, 0, 0),
             simulation_days=10,
             outfile=None,
             out_chunk_size=None,
             print_progress=False,
             seed=0,
             port=6688,
             n_jobs=1,
             other_monitors=[]):

    rng = np.random.RandomState(seed)
    env = Env(start_time)
    city_x_range = (0, 1000)
    city_y_range = (0, 1000)
    city = City(env, n_people, rng, city_x_range, city_y_range, start_time,
                init_percent_sick, Human)
    monitors = [
        EventMonitor(f=1800, dest=outfile, chunk_size=out_chunk_size),
        SEIRMonitor(f=1440)
    ]

    # run the simulation
    if print_progress:
        monitors.append(TimeMonitor(1440))  # print every day

    if other_monitors:
        monitors += other_monitors

    # run city
    all_possible_symptoms = [""] * len(SYMPTOMS_META)
    for k, v in SYMPTOMS_META.items():
        all_possible_symptoms[v] = k
    monitors[0].dump()
    monitors[0].join_iothread()
    env.process(
        city.run(1440, outfile, start_time, all_possible_symptoms, port,
                 n_jobs))

    # run humans
    for human in city.humans:
        env.process(human.run(city=city))

    # run monitors
    for m in monitors:
        env.process(m.run(env, city=city))

    env.run(until=simulation_days * 24 * 60 / TICK_MINUTE)

    return monitors, city.tracker
Esempio n. 3
0
def run_simu(n_people=None,
             init_percent_sick=0,
             start_time=datetime.datetime(2020, 2, 28, 0, 0),
             simulation_days=10,
             outfile=None,
             out_chunk_size=None,
             print_progress=False,
             seed=0,
             other_monitors=[]):

    rng = np.random.RandomState(seed)
    env = Env(start_time)

    city_x_range = (0, 1000)
    city_y_range = (0, 1000)
    city = City(env, n_people, rng, city_x_range, city_y_range, start_time,
                init_percent_sick, Human, simulation_days)

    monitors = [
        EventMonitor(f=120, dest=outfile, chunk_size=out_chunk_size),
        SEIRMonitor(f=1440)
    ]
    # run the simulation
    if print_progress:
        monitors.append(TimeMonitor(1440))  # print every day

    if other_monitors:
        monitors += other_monitors

    for human in city.humans:
        env.process(human.run(city=city))

    for m in monitors:
        env.process(m.run(env, city=city))
    env.run(until=simulation_days * 24 * 60 / TICK_MINUTE)

    return monitors, city.tracker
Esempio n. 4
0
def run_simu(n_stores=None,
             n_people=None,
             n_parks=None,
             n_misc=None,
             init_percent_sick=0,
             store_capacity=30,
             misc_capacity=30,
             start_time=datetime.datetime(2020, 2, 28, 0, 0),
             simulation_days=10,
             outfile=None,
             print_progress=False):
    env = Env(start_time)
    city_limit = ((0, 1000), (0, 1000))
    stores = [
        Location(
            env,
            capacity=_draw_random_discreet_gaussian(store_capacity,
                                                    int(0.5 * store_capacity)),
            cont_prob=0.1,
            location_type='store',
            name=f'store{i}',
            lat=random.randint(*city_limit[0]),
            lon=random.randint(*city_limit[1]),
        ) for i in range(n_stores)
    ]
    parks = [
        Location(env,
                 cont_prob=0.02,
                 name=f'park{i}',
                 location_type='park',
                 lat=random.randint(*city_limit[0]),
                 lon=random.randint(*city_limit[1])) for i in range(n_parks)
    ]
    households = [
        Location(
            env,
            cont_prob=1,
            name=f'household{i}',
            location_type='household',
            lat=random.randint(*city_limit[0]),
            lon=random.randint(*city_limit[1]),
        ) for i in range(int(n_people / 2))
    ]
    workplaces = [
        Location(
            env,
            cont_prob=1,
            name=f'workplace{i}',
            location_type='workplace',
            lat=random.randint(*city_limit[0]),
            lon=random.randint(*city_limit[1]),
        ) for i in range(int(n_people / 30))
    ]
    miscs = [
        Location(env,
                 cont_prob=1,
                 capacity=_draw_random_discreet_gaussian(
                     misc_capacity, int(0.5 * misc_capacity)),
                 name=f'misc{i}',
                 location_type='misc',
                 lat=random.randint(*city_limit[0]),
                 lon=random.randint(*city_limit[1])) for i in range(n_misc)
    ]

    humans = [
        Human(env=env,
              name=i,
              infection_timestamp=start_time
              if i < n_people * init_percent_sick else None,
              household=np.random.choice(households),
              workplace=np.random.choice(workplaces)) for i in range(n_people)
    ]

    city = City(stores=stores, parks=parks, humans=humans, miscs=miscs)
    monitors = [EventMonitor(f=120)]

    # run the simulation
    if print_progress:
        monitors.append(TimeMonitor(60))

    for human in humans:
        env.process(human.run(city=city))

    for m in monitors:
        env.process(m.run(env, city=city))
    env.run(until=simulation_days * 24 * 60 / TICK_MINUTE)

    monitors[0].dump(outfile)
    return monitors[0].data
Esempio n. 5
0
def run_simu(n_stores=None,
             n_people=None,
             n_parks=None,
             n_misc=None,
             init_percent_sick=0,
             store_capacity=30,
             misc_capacity=30,
             start_time=datetime.datetime(2020, 2, 28, 0, 0),
             simulation_days=10,
             outfile=None,
             print_progress=False,
             seed=0,
             Human=None):

    if Human is None:
        from simulator import Human

    rng = np.random.RandomState(seed)
    env = Env(start_time)
    city_limit = ((0, 1000), (0, 1000))
    total_area = (city_limit[0][1] - city_limit[0][0]) * (city_limit[1][1] -
                                                          city_limit[1][0])
    area_dict = {
        'store':
        _get_random_area('store', n_stores, total_area, rng),
        'park':
        _get_random_area('park', n_parks, total_area, rng),
        'misc':
        _get_random_area('misc', n_misc, total_area, rng),
        'household':
        _get_random_area('household', int(n_people / 2), total_area, rng),
        'workplace':
        _get_random_area('workplace', int(n_people / 30), total_area, rng)
    }

    stores = [
        Location(env,
                 rng,
                 capacity=_draw_random_discreet_gaussian(
                     store_capacity, int(0.5 * store_capacity), rng),
                 cont_prob=0.6,
                 location_type='store',
                 name=f'store{i}',
                 area=area_dict['store'][i],
                 lat=rng.randint(*city_limit[0]),
                 lon=rng.randint(*city_limit[1]),
                 surface_prob=[0.1, 0.1, 0.3, 0.2, 0.3])
        for i in range(n_stores)
    ]

    parks = [
        Location(env,
                 rng,
                 cont_prob=0.05,
                 name=f'park{i}',
                 area=area_dict['park'][i],
                 location_type='park',
                 lat=rng.randint(*city_limit[0]),
                 lon=rng.randint(*city_limit[1]),
                 surface_prob=[0.7, 0.05, 0.05, 0.1, 0.1])
        for i in range(n_parks)
    ]
    households = [
        Location(env,
                 rng,
                 cont_prob=1,
                 name=f'household{i}',
                 location_type='household',
                 area=area_dict['household'][i],
                 lat=rng.randint(*city_limit[0]),
                 lon=rng.randint(*city_limit[1]),
                 surface_prob=[0.05, 0.05, 0.05, 0.05, 0.8])
        for i in range(int(n_people / 2))
    ]
    workplaces = [
        Location(env,
                 rng,
                 cont_prob=0.3,
                 name=f'workplace{i}',
                 location_type='workplace',
                 area=area_dict['workplace'][i],
                 lat=rng.randint(*city_limit[0]),
                 lon=rng.randint(*city_limit[1]),
                 surface_prob=[0.1, 0.1, 0.3, 0.2, 0.3])
        for i in range(int(n_people / 30))
    ]
    miscs = [
        Location(env,
                 rng,
                 cont_prob=1,
                 capacity=_draw_random_discreet_gaussian(
                     misc_capacity, int(0.5 * misc_capacity), rng),
                 name=f'misc{i}',
                 area=area_dict['misc'][i],
                 location_type='misc',
                 lat=rng.randint(*city_limit[0]),
                 lon=rng.randint(*city_limit[1]),
                 surface_prob=[0.1, 0.1, 0.3, 0.2, 0.3]) for i in range(n_misc)
    ]

    humans = [
        Human(env=env,
              name=i,
              rng=rng,
              age=_get_random_age(rng),
              infection_timestamp=start_time
              if i < n_people * init_percent_sick else None,
              household=rng.choice(households),
              workplace=rng.choice(workplaces)) for i in range(n_people)
    ]

    city = City(stores=stores, parks=parks, humans=humans, miscs=miscs)
    monitors = [EventMonitor(f=120), SEIRMonitor(f=1440)]

    extra_info = {}
    extra_info['init_percent_sick'] = init_percent_sick
    extra_info['initial_states'] = [
        'infected' if i < n_people * init_percent_sick else 'not_infected'
        for i in range(n_people)
    ]
    extra_info['recovery_probs'] = [1.0 / h.recovery_days for h in humans]
    import json
    with open('extra_info.json', 'w') as f:
        json.dump(extra_info, f)

    # run the simulation
    if print_progress:
        monitors.append(TimeMonitor(60))

    for human in humans:
        env.process(human.run(city=city))

    for m in monitors:
        env.process(m.run(env, city=city))
    env.run(until=simulation_days * 24 * 60 / TICK_MINUTE)
    return monitors