How to manipulate an agent's specific attribute based on a condition in the model? #1681
-
I have created senders and carriers as two classes of agents. They have unique IDs. However, I want to change other attributes of a sender or a carrier using the unique id. Is there a way to create object names so that I can use them whenever needed to gain access to the object-specific attributes? I have tried the following but it throws an error: 'str' object has no attribute 'unique_id' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It depends on the scheduler class you are using. With Line 244 in dc4d5fc |
Beta Was this translation helpful? Give feedback.
I was able to create a dictionary with the key as the unique id of the agents and the value as the object name which looks like this:
<Abstract_crowdlogistics_model.Senders object at 0x7fd7dabe39d0>.
Now I am able to access Sender's attribute in a function that I defined in the Carrier agent class as shown below:
for i in self.model.Sender_population.keys():
if (self.model.Sender_population[i].Participation_status == "Y" and len(self.model.Sender_population[i].pickup_request_list)!= 0):
self.Potential_senders_to_match.append(i)