Example #1
0
    def init_testing(self):

        if (self.machines):
            self.testing_policy = Testing_Policy.Test_Policy(
                lambda x: self.num_agents_per_step)
            for machine in self.machines.keys():
                self.testing_policy.add_machine(machine,machines[machine]["cost"],machines[machine]["false_positive_rate"],\
                                                machines[machine]["false_negative_rate"],machines[machine]["turnaround_time"],machines[machine]["capacity"])

            if (self.option == "Normal Testing"):
                self.testing_policy.set_register_agent_testtube_func(
                    self.testing_policy.random_agents(1, 1))

            elif (self.option == "Group Testing"):
                num_agents_per_test = self.testing_methods_list[option][
                    "num_agents_per_test"]
                num_tests_per_agent = self.testing_methods_list[option][
                    "num_tests_per_agent"]
                self.testing_policy.set_register_agent_testtube_func(
                    self.testing_policy.random_agents(num_agents_per_test,
                                                      num_tests_per_agent))

            elif (self.option == "Friendship Testing"):
                min_days = self.testing_methods_list[option]["min_days"]
                self.testing_policy.set_register_agent_testtube_func(
                    self.testing_policy.friendship_testing(min_days))

            self.lockdown_policy = Lockdown_Policy.agent_policy_based_lockdown(
                "Testing", ["Positive"], lambda x: True,
                self.num_days_lockdown)
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
Example #3
0
def generate_policy():
    policy_list = []

    def lockdown_fn(time_step):
        return False

    policy_list.append(Lockdown_Policy.full_lockdown(lockdown_fn))

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

    return policy_list, event_restriction_fn
Example #4
0
def mt_no_grade2_wednesday_online():
    #This function ensures that there are no grade 1 students on Monday,tuesday and wednesday is online
    policy_list = []

    def lockdown_mt(time_step):
        if time_step % 7 in [0, 1]:
            return True
        return False

    def lockdown_wednesday(time_step):
        if time_step % 7 in [2]:
            return True
        return False

    policy_list.append(
        Lockdown_Policy.agent_lockdown('Grade', ['Grade 1'], lockdown_mt))
    policy_list.append(Lockdown_Policy.full_lockdown(lockdown_wednesday))

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

    return policy_list, event_restriction_fn
Example #5
0
def mw_no_grade1_tf_no_grade3():
    #This function ensures that there are no grade 1 students on Monday,Wednesday and grade 3 students on tuesday,friday
    policy_list = []

    def lockdown_mw(time_step):
        if time_step % 7 in [0, 2]:
            return True
        return False

    def lockdown_tf(time_step):
        if time_step % 7 in [1, 4]:
            return True
        return False

    policy_list.append(
        Lockdown_Policy.agent_lockdown('Grade', ['Grade 1'], lockdown_mw))
    policy_list.append(
        Lockdown_Policy.agent_lockdown('Grade', ['Grade 3'], lockdown_tf))

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

    return policy_list, event_restriction_fn
Example #6
0
def monday_tuesday_online():
    #This function ensures classes are online on Monday and Tuesday
    policy_list = []

    def lockdown_fn(time_step):
        if time_step % 7 in [1, 3]:
            return True
        return False

    policy_list.append(Lockdown_Policy.full_lockdown(lockdown_fn))

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

    return policy_list, event_restriction_fn
def generate_2D_infection_test_policy(num_tests, num_agents_per_test, num_tests_per_agent, dynamic=False):
    policy_list=[]

    # Group/Pool Testing
    Pool_Testing = Testing_Policy.Test_Policy(lambda x:-1)
    Pool_Testing.add_machine('Simple_Machine', 200, 0.0, 0.0, 0, 1000, 1)
    Pool_Testing.set_register_agent_testtube_func(Pool_Testing.random_agents_with_dynamic(num_tests, num_agents_per_test, num_tests_per_agent, dynamic))
    policy_list.append(Pool_Testing)

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

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

    return policy_list,event_restriction_fn
Example #8
0
def monday_no_grade1():
    #This function ensures that there are no grade 1 students on Monday
    policy_list = []

    def lockdown_fn(time_step):
        if time_step % 7 in [0]:
            return True
        return False

    policy_list.append(
        Lockdown_Policy.agent_lockdown('Grade', ['Grade 1'], lockdown_fn))

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

    return policy_list, event_restriction_fn
Example #9
0
def generate_policy():
    policy_list = []

    Pool_Testing = Testing_Policy.Test_Policy(lambda x: 3)
    Pool_Testing.add_machine('Simple_Machine', 200, 0.0, 0.0, 0, 50, 2)
    Pool_Testing.set_register_agent_testtube_func(
        Pool_Testing.random_agents(3, 2))
    policy_list.append(Pool_Testing)

    ATP = Lockdown_Policy.agent_policy_based_lockdown(
        "Testing", ["Positive"], lambda x: random.random() < 0.95, 10)
    policy_list.append(ATP)

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

    return policy_list, event_restriction_fn
def generate_fp_fn_policy(num_tests, fp, fn):
    policy_list=[]

    # Group/Pool Testing
    print(num_tests,fp,fn)
    Pool_Testing = Testing_Policy.Test_Policy(lambda x:num_tests)
    Pool_Testing.add_machine('Simple_Machine', 200, fp, fn, 0, 1000, 1)
    Pool_Testing.set_register_agent_testtube_func(Pool_Testing.random_agents(1,1))
    policy_list.append(Pool_Testing)

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

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

    return policy_list,event_restriction_fn
def generate_group_testing_tests_policy_turn(num_tests, num_agents_per_test, num_tests_per_agent, turn):
    policy_list=[]

    # Group/Pool Testing
    num_agents = int(np.floor(num_tests*num_agents_per_test/num_tests_per_agent))
    print(num_agents,num_agents_per_test,num_tests_per_agent)
    Pool_Testing = Testing_Policy.Test_Policy(lambda x:num_agents)
    Pool_Testing.add_machine('Simple_Machine', 200, 0.0, 0.0, turn, 1000, 1)
    Pool_Testing.set_register_agent_testtube_func(Pool_Testing.random_agents(num_agents_per_test,num_tests_per_agent))
    policy_list.append(Pool_Testing)

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

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

    return policy_list,event_restriction_fn
def generate_group_testing_colab(napt,ntpa,testing_gap,tests_per_period,turnaround_time,restriction_time,fn,fp):

    testing_gap+=1

    policy_list=[]

    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', 0, 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
    return policy_list,event_restriction_fn