Beispiel #1
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)
Beispiel #2
0
 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)
 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)
Beispiel #4
0
 def start_round(self, message: Message):
     print("Start round message received... forwarding to institution")
     message = Message()
     message.set_sender(self)
     message.set_recipients(self.institutions[0])
     message.set_directive("start_round")
     self.send(self.institutions[0], message)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 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
Beispiel #8
0
 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
Beispiel #9
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
Beispiel #10
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
Beispiel #11
0
 def start_auction(self, message: Message):
     if self.mtree_properties["num_auctions"] > 0:
         self.mtree_properties[
             "num_auctions"] = self.mtree_properties["num_auctions"] - 1
         print("INSTITUTION: Starting Auction")
         self.agents = message.get_payload()["agents"]
         self.bids = []
         self.bids_outstanding = len(self.agents)
         self.item_for_auction = random.randint(self.min_item_value,
                                                self.max_item_value)
         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("item_for_bidding")
             new_message.set_payload({
                 "min_value": self.min_item_value,
                 "max_value": self.max_item_value
             })
             self.send(agent, new_message)  # receiver_of_message, message
     else:
         print("AUCTIONS COMPLETED")
         new_message = Message()  # declare message
         new_message.set_sender(
             self.myAddress)  # set the sender of message to this actor
         new_message.set_directive("close_environment")
         self.send(self.environment,
                   new_message)  # receiver_of_message, message
Beispiel #12
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)
 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
Beispiel #14
0
    def launch_simulation(self):
        """ DEPRECATED """
        
        component_registry = registry.Registry()

        environment = component_registry.get_component_class(self.configuration["environment"])
        institution = component_registry.get_component_class(self.configuration["institution"])
        agents = []
        for agent_d in self.configuration["agents"]:
            agent_class = component_registry.get_component_class(agent_d["agent_name"])
            agent_count = agent_d["number"]
            agents.append((agent_class, agent_count))

        container = Container()
        properties = None
        if "properties" in self.configuration.keys():
            properties = self.configuration["properties"]
        container.create_root_environment(environment, properties)
        container.setup_environment_institution(institution)
        for agent in agents:
            container.setup_environment_agents(agent[0], agent[1])

        start_message = Message()
        start_message.set_sender("experimenter")
        start_message.set_directive("start_environment")
        container.send_root_environment_message(start_message)
Beispiel #15
0
    def initialize_agents(self, message: Message):
        '''give each of the agents their attributes and sends the info to institution for data collecting'''

        # contains the theta and sd
        payload = message.get_payload()
        #self.theta = payload["theta"]
        #self.sd = payload["sd"]

        #make the message to send to each agent
        message = Message()
        message.set_sender(self)
        message.set_directive("initialize_agents")
        message.set_payload(payload)

        #send message to all agents
        for agent in self.agents:
            self.send(agent, message)

        #create message for the institution
        message = Message()
        message.set_sender(self)
        message.set_directive("theta_sd")
        message.set_payload(payload)

        #send the theta and delta to the institution for data collection
        for institution in self.institutions:
            self.send(institution, message)
 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
Beispiel #17
0
 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
Beispiel #18
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
Beispiel #19
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
Beispiel #20
0
 def kill_run_by_id(self, run_id):
     dispatcher = ActorSystemConnector.__instance.actor_system.createActor(Dispatcher, globalName = "Dispatcher") #ActorSystem("multiprocTCPBase", self.capabilities).createActor(Dispatcher, globalName = "Dispatcher")
     configuration_message = Message()
     configuration_message.set_directive("kill_run_by_id")
     payload = {}
     payload["run_id"] = run_id
     configuration_message.set_payload(payload)
     ActorSystemConnector.__instance.actor_system.tell(dispatcher, configuration_message)
 def register_for_collateral(self, message: Message):
     self.agents = message.get_payload()["agents"]
     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("register_for_collateral")
         self.send(agent, new_message)  # receiver_of_message, message
Beispiel #22
0
 def agent_action_forward(self, message: Message):
     subject_id = message.get_payload()["subject_id"]
     subject_agent_map = self.subject_map[subject_id]
     new_message = Message()
     new_message.set_directive(message.get_payload()["action"])
     new_message.set_sender(self.myAddress)
     new_message.set_payload(message.get_payload())
     self.send(subject_agent_map, new_message)
Beispiel #23
0
    def setup_agent_requests(self, message: Message):
        if "address_book" not in dir(self):
            self.address_book = AddressBook(self)

        if "agents" not in dir(self):
            self.agents = []
            self.agent_addresses = []
        # ensure that the actor system and institution are running...
        #message = MessageSpace.create_agent(agent_class)
        num_agents = message.get_payload().number
        agent_class = message.get_payload().source_class

        # need to check source hash for simulation
        source_hash = message.get_payload().source_hash

        # memory = False
        # agent_memory = None
        # if "agent_memory" in message.get_payload().keys():
        #     memory = True
        #     agent_memory = message.get_payload()["agent_memory"]

        if "subjects" in dir(self):
            self.subject_map = {}

        for i in range(num_agents):
            agent_number = i + 1
            new_agent = self.createActor(agent_class, sourceHash=source_hash)
            self.send(new_agent, agent_class + " " + str(agent_number))
            self.agent_addresses.append(new_agent)
            self.agents.append([new_agent, agent_class])

            agent_info = {}
            agent_info["address_type"] = "agent"
            agent_info["address"] = new_agent
            agent_info["component_class"] = agent_class
            agent_info["component_number"] = agent_number
            agent_info["short_name"] = agent_class + " " + str(agent_number)

            self.address_book.add_address(agent_info["short_name"], agent_info)

            new_message = Message()
            #new_message.set_sender(self.myAddress)
            new_message.set_directive("simulation_properties")
            new_message.set_sender(self.myAddress)
            payload = {}
            #if "mtree_properties" not in dir(self):
            payload["log_actor"] = self.log_actor
            #payload["dispatcher"] = self.createActor("Dispatcher", globalName="dispatcher")
            payload["properties"] = self.mtree_properties
            payload["agent_information"] = agent_info
            if "subjects" in dir(self):
                payload["subject_id"] = self.subjects[i]["subject_id"]
                self.subject_map[payload["subject_id"]] = new_agent

            # if memory:
            #     payload["agent_memory"] = agent_memory
            new_message.set_payload(payload)
            self.send(new_agent, new_message)
Beispiel #24
0
 def setup_environment_agents(self, agent_class, num_agents=1):
     #logging.info("AGENTS BEING SETUP FROM ENV")
     message = Message()
     message.set_directive("setup_agents")
     message.set_payload({
         "agent_class": agent_class,
         "num_agents": num_agents
     })
     self.actor_system.tell(self.environment, message)
Beispiel #25
0
 def setup_environment_institution(self, environment_address,
                                   institution_class):
     classname = institution_class.__module__ + "." + institution_class.__name__
     message = Message()
     message.set_directive("setup_institution")
     message.set_payload({"institution_class": institution_class})
     self.actor_system.tell(self.environments[environment_address],
                            message)
     logging.info("INSTITUTION STARTED")
Beispiel #26
0
 def create_root_environment(self, environment_class, properties=None):
     print("CREATING AN ENVIRONMENT")
     print(properties)
     self.environment = self.actor_system.createActor(environment_class)
     if properties is not None:
         message = Message()
         message.set_directive("simulation_properties")
         message.set_payload({"properties": properties})
         self.actor_system.tell(self.environment, message)
Beispiel #27
0
 def excepted_mes(self, message: Message):
     new_message = Message()
     new_message.set_sender(self.myAddress)
     new_message.set_directive("excepted_mes")
     try:
         new_message.set_payload(message.get_payload())
     except:
         new_message.set_payload(message)
     self.send(self.dispatcher, new_message)
Beispiel #28
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
 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))
Beispiel #30
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)