コード例 #1
0
    def one_world(self):

        time_steps = self.config_obj.time_steps

        #Initialize agents
        agents_obj = ReadFile.ReadAgents(self.agents_filename, self.config_obj)

        #Intialize locations
        locations_obj = ReadFile.ReadLocations(self.locations_filename,
                                               self.config_obj)

        sim_obj = Simulate.Simulate(self.config_obj, self.model,
                                    self.policy_list,
                                    self.event_restriction_fn, agents_obj,
                                    locations_obj)
        sim_obj.onStartSimulation()

        for i in range(time_steps):
            if self.interactionFiles_list == [] or self.interactionFiles_list == None:
                interactions_filename = None
            else:
                interactions_filename = self.interactionFiles_list[i % len(
                    self.interactionFiles_list)]
            if self.eventFiles_list == [] or self.eventFiles_list == None:
                events_filename = None
            else:
                events_filename = self.eventFiles_list[i % len(
                    self.eventFiles_list)]

            sim_obj.onStartTimeStep(interactions_filename, events_filename, i)
            sim_obj.handleTimeStepForAllAgents()
            sim_obj.endTimeStep()

        end_state, machine_cost = sim_obj.endSimulation()
        total_quarantined_days = 0
        wrongly_quarantined_days = 0
        total_positives = 0
        total_false_positives = 0

        for policy in self.policy_list:
            if (isinstance(policy, Test_Policy)):
                self.total_positive_pools += policy.positive_pools

        for agent in agents_obj.agents.values():
            for truth in agent.quarantine_list:
                if (truth == "Right"):
                    total_quarantined_days += 1
                elif (truth == "Wrong"):
                    total_quarantined_days += 1
                    wrongly_quarantined_days += 1

            history = agent.get_policy_history("Testing")
            if (len(history)):
                t_f_p, t_p = get_accumulated_result(agent, history)
                total_false_positives += t_f_p
                self.total_positives += t_p

        self.total_quarantined_days += total_quarantined_days
        self.wrongly_quarantined_days += wrongly_quarantined_days
        self.total_infection += len(
            agents_obj.agents) - end_state["Susceptible"][-1]
        self.total_machine_cost += machine_cost
        self.total_false_positives += total_false_positives

        return end_state, agents_obj, locations_obj
コード例 #2
0
 def init_scores(self):
     agents_obj = ReadFile.ReadAgents(self.world_obj.agents_filename,
                                      self.world_obj.config_obj)
     for agent_index in agents_obj.agents.keys():
         self.agent_scores[agent_index] = 0