コード例 #1
0
 def list_agents(cls):
     message = Message()
     message.set_sender("Environment")  # SPECIAL CASE Environment
     message.set_recipients("Institution")
     message.set_directive("list_agents")
     message.set_payload(None)
     return message
コード例 #2
0
ファイル: basic_agent.py プロジェクト: gmucsn/mTree_examples
 def item_for_bidding(self, message: Message):
     self.min_value = message.get_payload()["min_value"]
     self.max_value = message.get_payload()["max_value"]
     self.institution = message.get_sender()
     logging.log(EXPERIMENT, "Agent received item for bid %s - %s",
                 str(self.min_value), str(self.max_value))
     self.make_bid()
コード例 #3
0
ファイル: environment.py プロジェクト: gmucsn/mTree
    def logger_setup(self, message: Message):
        self.log_actor = self.createActor(
            "log_actor.LogActor")  #, globalName="log_actor")

        log_basis = {}
        log_basis["message_type"] = "setup"

        # setting short name for environment
        #self.short_name = message.get_payload()["short_name"]
        logging.info("ENVIRONMENT should have : " + str(message.get_payload()))

        short_name = message.get_payload()["short_name"]
        # self.short_name = "environment"

        # if "address_book" not in dir(self):
        #     self.address_book = AddressBook(self)

        # logging.info("ENVIRONMENT short name is : " + str(self.short_name))

        log_basis["simulation_run_id"] = message.get_payload(
        )["simulation_run_id"]
        log_basis["simulation_id"] = message.get_payload()["simulation_id"]
        log_basis["run_number"] = message.get_payload(
        )["simulation_run_number"]
        log_basis["run_code"] = message.get_payload()["run_code"]
        log_basis["status"] = message.get_payload()["status"]
        log_basis["mes_directory"] = message.get_payload()["mes_directory"]
        log_basis["data_logging"] = message.get_payload()["data_logging"]
        log_basis["simulation_configuration"] = message.get_payload(
        )["simulation_configuration"]
        self.send(self.log_actor, log_basis)
コード例 #4
0
 def bid_at_price(self, message: Message):
     self.current_price = message.get_payload()["current_price"]
     self.institution = message.get_sender()
     self.log_data("Agent alerted that current price is " +
                   str(self.current_price))
     if self.current_price < self.max_bid:
         self.make_bid()
コード例 #5
0
 def accept_bid(self, message: Message):
     bidder = message.get_sender()
     bid = message.get_payload()["bid"]
     self.bids.append((bid, bidder))
     self.bids_outstanding -= 1
     if self.bids_outstanding == 0:
         self.complete_auction()
コード例 #6
0
 def start_agents(self, message: Message):
     print("About to start agents")
     for agent in self.agents:
         message = Message()
         message.set_sender(self)
         message.set_directive("start_agent")
         self.send(agent, message)
コード例 #7
0
 def create_agent(cls, agent_class):
     message = Message()
     message.set_sender("Universe")  # SPECIAL CASE Environment
     message.set_recipients("Environment")
     message.set_directive("create_agent")
     message.set_payload(agent_class)
     return message
コード例 #8
0
 def request_agent_list(cls):
     print("AGENT LIST REQUESTED")
     message = Message()
     message.set_sender("Institution")  # SPECIAL CASE Environment
     message.set_recipients("Environment")
     message.set_directive("request_agent_list")
     message.set_payload(None)
     return message
コード例 #9
0
 def bid_for_item(self, message: Message):
     bidder = message.get_sender()
     bid = int(message.get_payload()["bid"])
     if bid > self.last_bid:
         self.last_bid = bid
         self.last_bid_time = time.time()
         self.bids.append((bid, bidder))
         self.alert_agents_of_price(self.last_bid)
コード例 #10
0
 def auction_result(self, message: Message):
     #logging.log(EXPERIMENT, "Agent received item for bid %s", message.get_payload())
     if message.get_payload()["status"] == "winner":
         if "win_rate" not in self.agent_memory.keys():
             self.agent_memory["win_rate"] = 0
         self.agent_memory["win_rate"] = self.agent_memory["win_rate"] + 1 
     elif message.get_payload()["status"] == "loser":
         if "loss_rate" not in self.agent_memory.keys():
             self.agent_memory["loss_rate"] = 0
         self.agent_memory["loss_rate"] = self.agent_memory["loss_rate"] + 1 
コード例 #11
0
 def get_status(self):
     if len(self.__instance.dispatchers) == 0:
         return []
     else:
         dispatcher = ActorSystemConnector.__instance.actor_system.createActor(Dispatcher, globalName = "Dispatcher")# ActorSystem("multiprocTCPBase", self.capabilities).createActor(Dispatcher, globalName = "Dispatcher")
         configuration_message = Message()
         configuration_message.set_directive("check_status")
         response = ActorSystemConnector.__instance.actor_system.ask(dispatcher, configuration_message) #.createActor(Dispatcher, globalName = "Dispatcher")
         # ActorSystem("multiprocTCPBase", self.capabilitie).ask(dispatcher, configuration_message)
         return response
コード例 #12
0
    def start_experiment(self, message: Message):
        '''Start the actual experiment'''

        message = Message()
        message.set_sender(self)
        message.set_directive("start_experiment")

        #send the message to all institutions
        for i in self.institutions:
            self.send(i, message)
コード例 #13
0
ファイル: basic_agent.py プロジェクト: gmucsn/mTree_examples
 def auction_result(self, message: Message):
     logging.log(EXPERIMENT, "Agent received item for bid %s", message.get_payload())
     new_message = Message()  # declare message
     new_message.set_sender(self.myAddress)  # set the sender of message to this actor
     new_message.set_directive("register_collateral")
     new_message.set_payload({"bid": self.min_value})
     self.send(self.collateral_institution, new_message)  # receiver_of_message, message
コード例 #14
0
ファイル: environment.py プロジェクト: gmucsn/mTree
 def update_mes_status(self, message: Message = None):
     new_message = Message()
     new_message.set_sender(self.myAddress)
     new_message.set_directive("update_mes_status")
     payload = message.get_payload()
     new_message.set_payload(payload)
     self.send(self.log_actor, new_message)
コード例 #15
0
    def collect_data(self, message: Message):
        '''tells in institution to send the data to the container'''

        #create message
        message = Message()
        message.set_sender(self)
        message.set_directive("collect_data")

        #send to all institutions
        for i in self.institutions:
            self.send(i, message)
コード例 #16
0
    def new_season(self, message: Message):
        """
        Receives information about the start of the new epidemic season, whenever a new season starts. 
        """

        if self.debug:
            logging.log(EXPERIMENT,
                        f'agent {self.unique_id} entered new_season')

        choice = message.get_payload()["choice"]
        seed = message.get_payload()["seed"]
        new_season_state = message.get_payload()["new_season_state"]
        prob_of_infection = message.get_payload()["prob_of_infection"]

        #agents who were vaccinated in the previous season should remain vaccinated
        if self.current_state == 'V' and new_season_state != 'V':
            logging.log(
                EXPERIMENT,
                f"ERROR: Agent {self.unique_id} somehow lost vaccination at the beginning of a new season"
            )

        #update your current state for the new season
        self.current_state = new_season_state

        #if the agent was offered a choice, decide whether or not to get vaccinated
        if choice:
            if prob_of_infection >= (
                    1 / self.cost_of_infection
            ):  #get vaccinated if the probability of infection is high in your region
                self.current_state = 'V'
            else:  #if the probability of infection is not so high, start the season susceptible
                self.current_state = 'S'

        #finally, consider whether this agent is a seed of the infection
        if seed:
            if self.current_state != 'V':  #if a seed agent is not vaccinated, they start the season Infected
                self.current_state = 'In'

        if self.debug:
            logging.log(
                EXPERIMENT,
                f"Agent {self.unique_id} is facing a prob_of_infection of {prob_of_infection} "
                f"in hub {self.hub}, along with a cost_of_infection of {self.cost_of_infection}."
            )

        #register with the insitution again. The institution will figure out whether/how the simulation should proceed
        self.start_registration()

        if self.debug:
            logging.log(EXPERIMENT,
                        f'agent {self.unique_id} exited new_season')
コード例 #17
0
ファイル: institution.py プロジェクト: gmucsn/mTree
 def shutdown_mes(self):
     new_message = Message()
     new_message.set_directive("shutdown_mes")
     new_message.set_sender(self.myAddress)
     payload = {}
     new_message.set_payload(payload)
     self.send(self.environment, new_message)
コード例 #18
0
    def init_agents(self, message: Message):
        """
        Receives the initial state of the agent from the environment,
        either susceptible or infected.
        """
        if self.debug:
            logging.log(EXPERIMENT,
                        f'agent {self.unique_id} entered init_agents')

        #save the agent's current SIS state from the environment, plus the institution's address
        self.current_state = message.get_payload()["current_state"]
        self.hub = message.get_payload()["hub"]
        self.institution_address = message.get_payload()["institution_address"]
        self.environment_address = message.get_sender().myAddress

        #save data about the SEIR simulation
        self.number_of_agents = message.get_payload()["number_of_agents"]
        self.rate_of_infection_per_contact = message.get_payload(
        )["rate_of_infection_per_contact"]
        self.recovery_rate = message.get_payload()["recovery_rate"]
        self.incubation_period = message.get_payload()["incubation_period"]
        self.cost_of_infection = message.get_payload()["cost_of_infection"]

        #create a unique_id for this agent
        self.unique_id = 'A' + str(datetime.now()) + str(
            random.randrange(0, 100000000))

        #register with the matching institution for the first time
        self.start_registration()

        if self.debug:
            logging.log(EXPERIMENT,
                        f'agent {self.unique_id} exited init_agents')
コード例 #19
0
 def forward_address_book(self, address):
     new_message = Message()
     new_message.set_sender(self.base_component.myAddress)
     new_message.set_directive("address_book_update")
     new_message.set_payload(self.addresses)
     #address = self.select_addresses(selector)
     self.base_component.send(address, new_message)
コード例 #20
0
ファイル: basic_agent.py プロジェクト: gmucsn/mTree_examples
 def make_bid(self):
     new_message = Message()  # declare message
     new_message.set_sender(self)  # set the sender of message to this actor
     new_message.set_directive("bid_for_item")
     new_message.set_payload({"bid": self.min_value})
     self.send(self.institution.myAddress,
               new_message)  # receiver_of_message, message
コード例 #21
0
 def start_auction(self):
     new_message = Message()  # declare message
     new_message.set_sender(self)  # set the sender of message to this actor
     new_message.set_directive("start_auction")
     new_message.set_payload({"agents": self.agents})
     self.send(self.institutions[0],
               new_message)  # receiver_of_message, message
コード例 #22
0
ファイル: environment.py プロジェクト: gmucsn/mTree
 def shutdown_mes(self, message: Message = None):
     new_message = Message()
     new_message.set_sender(self.myAddress)
     new_message.set_directive("shutdown_mes")
     payload = {}
     new_message.set_payload(payload)
     self.send(self.dispatcher, new_message)
コード例 #23
0
 def initialize_agents(self):
     for agent in self.agents:
         new_message = Message()
         new_message.set_sender(self)
         new_message.set_directive("<INSERT DIRECTIVE NAME>")
         new_message.set_payload({"<PAYLOAD>": "<PAYLOAD VALUE>"})
         self.send(agent[0], new_message)
コード例 #24
0
 def provide_endowment(self):
     endowment = self.mtree_properties["agent_endowment"]
     for agent in self.agent_addresses:
         new_message = Message()  # declare message
         new_message.set_sender(self.myAddress)  # set the sender of message to this actor
         new_message.set_directive("set_endowment")  # Set the directive (refer to 3. Make Messages) - has to match reciever decorator
         new_message.set_payload({"endowment": endowment})
         self.send(agent, new_message )  # receiver_of_message, message
コード例 #25
0
 def initialize_round(self, message: Message):
     print(
         "About to initialize an experiment round by sending a messsage to the institution"
     )
     # initialize institution by alerting to agents
     message = Message()
     message.set_directive("initialize_institution")
     message.set_payload({"agent_list": self.agents})
     self.send(self.institutions[0], message)
     # initialize agents by alerting to institution
     message = Message()
     message.set_directive("initialize_agent")
     message.set_payload({"institution": self.institutions[0]})
     for agent in self.agents:
         self.send(agent, message)
コード例 #26
0
 def alert_agents_of_price(self, current_price):
     for agent in self.agents:
         new_message = Message()  # declare message
         new_message.set_sender(
             self.myAddress)  # set the sender of message to this actor
         new_message.set_directive("current_price")
         new_message.set_payload({"current_price": current_price})
         self.send(agent, new_message)  # receiver_of_message, message
コード例 #27
0
ファイル: basic_agent.py プロジェクト: gmucsn/mTree_examples
 def make_bid(self):
     print("Making a bid... Total Endowment: ", self.endowment)
     self.mtree_properties
     new_message = Message()  # declare message
     new_message.set_sender(self.myAddress)  # set the sender of message to this actor
     new_message.set_directive("bid_for_item")
     new_message.set_payload({"bid": self.min_value})
     self.send(self.institution, new_message)  # receiver_of_message, message
コード例 #28
0
    def initialize_rows(self, message: Message):
        '''makes the rows of the choices as list of tuples'''
        payload = message.get_payload()

        #set the rewards
        reward_A_1 = payload["reward_A_1"]
        reward_A_2 = payload["reward_A_2"]
        reward_B_1 = payload["reward_B_1"]
        reward_B_2 = payload["reward_B_2"]
        num_rows = payload["num_rows"]  # number of rows in the bundle

        # creates each row and append to bundle
        for i in range(1, num_rows + 1):
            optionA = ([((i / num_rows), reward_A_1),
                        ((((num_rows - i) / num_rows)), reward_A_2),
                        "A_%d" % i])
            optionB = ([((i / num_rows), reward_B_1),
                        ((((num_rows - i) / num_rows)), reward_B_2),
                        "B_%d" % i])
            self.bundle.append([optionA,
                                optionB])  # append each row to the bundle

        self.experiment = payload["experiment"]
        self.total_experiments = payload["total_experiments"]
        self.run = payload["run"]
        self.total_runs = payload["total_runs"]
コード例 #29
0
 def start_auction(self, message: Message):
     if self.auctions > 0:
         self.auctions -= 1
         self.agents = message.get_payload()["agents"]
         self.bids = []
         self.starting_price = random.randint(self.min_item_value,
                                              self.max_item_value)
         self.alert_agents_of_price(self.starting_price)
コード例 #30
0
 def make_bid(self):
     new_message = Message()  # declare message
     new_message.set_sender(
         self.myAddress)  # set the sender of message to this actor
     new_message.set_directive("bid_for_item")
     self.last_bid = self.current_price + self.bid_increment
     new_message.set_payload({"bid": self.last_bid})
     self.send(self.institution,
               new_message)  # receiver_of_message, message
     self.log_message("Agent submitted bid: " + str(self.last_bid))