def run_simulation(test_cost, fp_cost, quarantine_cost, infection_cost, n, p,
                   beta, gamma, napt, ntpa, testing_gap, tests_per_period,
                   turnaround_time, restriction_time, fn, fp):

    testing_gap += 1

    config_filename = get_config_path('')

    # Read Config file using ReadFile.ReadConfiguration
    config_obj = ReadFile.ReadConfiguration(config_filename)

    agents_filename = 'agents.txt'
    interactions_files_list = ['interactions_list.txt']
    locations_filename = None
    events_files_list = []

    # User Model
    model = get_model(beta, gamma)

    ##########################################################################################

    policy_list = []

    # Group/Pool Testing
    def testing_fn(timestep):
        if timestep % testing_gap == 0:
            return tests_per_period * napt / ntpa
        return 0

    Pool_Testing = Testing_Policy.Test_Policy(testing_fn)
    Pool_Testing.add_machine('Simple_Machine', test_cost, fp, fn,
                             turnaround_time, 1000, 1)
    Pool_Testing.set_register_agent_testtube_func(
        Pool_Testing.random_agents(napt, ntpa))
    policy_list.append(Pool_Testing)

    ATP = Lockdown_Policy.agent_policy_based_lockdown("Testing", ["Positive"],
                                                      lambda x: True,
                                                      restriction_time)
    policy_list.append(ATP)

    def event_restriction_fn(agent, event_info, current_time_step):
        return False

    ###############################################################################################

    world_obj = World.World(config_obj, model, policy_list,
                            event_restriction_fn, agents_filename,
                            interactions_files_list, locations_filename,
                            events_files_list)
    # world_obj.simulate_worlds(plot=True)
    tdict, total_infection, total_quarantined_days, wrongly_quarantined_days, total_test_cost = world_obj.simulate_worlds(
        plot=False)
    cost = total_infection * infection_cost + total_quarantined_days * quarantine_cost + total_test_cost + world_obj.total_false_positives * fp_cost
    return cost
Esempio n. 2
0
    def __init__(self,example_path):
        self.path=example_path

        config_filename = self.get_config_path()

        # Read Config file using ReadFile.ReadConfiguration
        config_obj=ReadFile.ReadConfiguration(config_filename)

        agents_filename, interactions_FilesList_filename,\
        events_FilesList_filename, locations_filename = self.get_file_paths(config_obj)
        interactions_files_list, events_files_list = self.get_file_names_list(interactions_FilesList_filename,events_FilesList_filename,config_obj)

        # User Model and Policy
        model = self.get_model()
        policy_list, event_restriction_fn=self.get_policy()

        # Creation of World object
        self.world_obj = World.World(config_obj,model,policy_list,event_restriction_fn,agents_filename,interactions_files_list,locations_filename,events_files_list)
Esempio n. 3
0
    UserModel = module_from_file("Generate_model", osp.join(example_path,'UserModel.py'))
    model = UserModel.UserModel()
    return model

def get_policy(example_path):
    Generate_policy = module_from_file("Generate_policy", osp.join(example_path,'Generate_policy.py'))
    policy_list, event_restriction_fn=Generate_policy.generate_policy()
    return policy_list, event_restriction_fn

if __name__=="__main__":

    example_path = get_example_path()
    config_filename = get_config_path(example_path)

    # Read Config file using ReadFile.ReadConfiguration
    config_obj=ReadFile.ReadConfiguration(config_filename)

    agents_filename, interactions_FilesList_filename,\
    events_FilesList_filename, locations_filename = get_file_paths(example_path,config_obj)
    interactions_files_list, events_files_list = get_file_names_list(example_path,interactions_FilesList_filename,events_FilesList_filename,config_obj)

    # User Model
    model = get_model(example_path)

    ##########################################################################################

    fp = open("2D_time_series.txt","w")
    num_tests = 90
    pools_list = [(None,None),(1,1),(2,1),(3,2)]
    tdicts = []
    for i,j in pools_list: