How can i get the Mesa agent using their unique_id in Python?

304 views Asked by At

I am using the Python library Mesa for modeling a multiagent system. Is there a way to get the agent itself if you just have its unique_id? I have one agent save the id of another agent, which at a later point in time the agent tries to interact with. Is there a method of the model or grid that takes the id and gives back the correlating agent?

1

There are 1 answers

0
Clark On

Yes, you can access an agent and any attributes you've assigned to its class by via the scheduler, which is an ordered dictionary:

For example, in the step function for your agents you can access the ID of the agent of interest via self.model.schedule._agents[ID] and if there's a certain attribute you're looking for, you'd use self.model.schedule._agents[ID].attribute_of_interest

I know this is quite a bit after you posted but I'm getting really into MESA and trying to expand the knowledge. Good luck!