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()
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()
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()
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')
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)
def simulation_properties(self, message: Message): self.dispatcher = message.get_sender() #self.log_actor = message.get_payload()["log_actor"] if "mtree_properties" not in dir(self): self.mtree_properties = {} self.mtree_properties = message.get_payload()["properties"] self.simulation_id = message.get_payload()["simulation_id"] self.simulation_run_id = message.get_payload()["simulation_run_id"] if "subjects" in message.get_payload().keys(): self.subjects = message.get_payload()["subjects"] logging.info("Subjects list available...") logging.info(self.subjects) # if "subjects" in message.get_payload()["properties"].keys(): # self.subjects = message.get_payload()["properties"]["subjects"] # logging.info("Subjects list available...") # logging.info(self.subjects) if "run_number" in message.get_payload().keys(): self.run_number = message.get_payload()["run_number"]
def register_for_collateral(self, message: Message): self.collateral_institution = message.get_sender()
def register(self, message: Message): """ Receives registration from each agent and compiles a list of registered agents. When the length of that list matches self.number_of_agents, start time_period 0. """ if self.debug: logging.log(EXPERIMENT, "institution entered register") #save the address, current_state, and group of the registering agent agent_address = message.get_sender().myAddress current_state = message.get_payload()["current_state"] agent_hub = message.get_payload()["hub"] #if this is the first agent to be registered in this time period, initialize a new dictionary if len(self.time_period_data[self.season]) == self.time_period: self.time_period_data[self.season].append({}) #add this agent to the record for the time period self.time_period_data[self.season][ self.time_period][f"{agent_address}"] = {} #start a record of all registered agents: self.registered_agents.append(agent_address) #add the agent to the list for its hub self.dict_of_hubs[agent_hub]['agents'].append(agent_address) if self.time_period == 0 and self.season == 0: #generate the agent's entry in the network structure dictionary self.network_structure[f"{agent_address}"] = {} self.network_structure[f"{agent_address}"]["hub"] = agent_hub self.network_structure[f"{agent_address}"]["neighbors"] = [] self.network_structure[f"{agent_address}"][ "number_of_connections"] = self.dict_of_hubs[agent_hub][ "number_of_connections"] if self.debug: logging.log( EXPERIMENT, f"INSTITUTION: registered agent = {agent_address} from hub = {agent_hub}" ) #we need to calculate the number of infected agents. When this number is 0, end this season. if current_state == 'In': self.number_of_infected += 1 #find out whether the agent is currently susceptible, exposed, infectious, or recovered self.time_period_data[self.season][self.time_period][ f"{agent_address}"]["starting_state"] = current_state #log the number of registered agents so far if self.debug: logging.log( EXPERIMENT, f"INSTITUTION: registered_agents = {len(self.registered_agents)}, number of agents = {self.number_of_agents}, number of infected = {self.number_of_infected}" ) #when the number of registered agents matches the total number of agents, start the simulation #also check that there are still any infected agents if len(self.registered_agents ) == self.number_of_agents and self.number_of_infected > 0: #in the first time_period of the first season, generate a random network structure if self.time_period == 0 and self.season == 0: self.generate_heterogeneous_network() #in all time periods, process one round of the simulation and notify agents of exposure status self.run_basic_simulation() self.notify_agents() self.time_period += 1 #move to the next time period self.registered_agents = [ ] #reinitialize the registered_agents list for the next time period self.number_of_infected = 0 #reinitialize the number of infected for the next time period elif len(self.registered_agents ) == self.number_of_agents and self.number_of_infected == 0: self.start_new_season() self.registered_agents = [ ] #reinitialize the registered_agents list for the next time period self.number_of_infected = 0 #reinitialize the number of infected for the next time period self.registered_agents = [ ] #reinitialize the registered_agents list for the next time period self.number_of_infected = 0 #reinitialize the number of infected for the next time period if self.debug: logging.log(EXPERIMENT, "institution exited register")
def bid_at_price(self, message: Message): self.current_price = message.get_payload()["current_price"] self.institution = message.get_sender() self.log_data("Agent received item for bid " + str(self.current_price)) if self.current_price < self.max_bid: self.make_bid()