find agent by id

9 views
Skip to first unread message

Yilin Huang

unread,
Feb 2, 2021, 6:16:41 PMFeb 2
to ProjectMesa

Hi all,
I am new to Mesa.
I would like to find agent reference by unique_id. is it possible to do this in Mesa without managing the references myself?
Many thanks in advance.
Yilin

Conor Artman

unread,
Feb 3, 2021, 12:22:22 PMFeb 3
to Yilin Huang, ProjectMesa
Hi Yilin,

If you're just getting started, please take a look at this repo's walkthrough for using MESA for fast ABM prototyping and modeling: https://github.com/cma43/Open-ABM/blob/master/Introductory%20Walkthrough/oabm_intro_walkthrough.ipynb

As for your question, generally an instance of an agent will have at least a private attribute called _unique_id, but in MESA's walkthroughs you'll see that it's not hard to construct an agent with a unique_id attribute.

Thanks,
Conor

--
Project repos: github.com/projectmesa
---
You received this message because you are subscribed to the Google Groups "ProjectMesa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectmesa...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectmesa/9b811511-2e6b-4a1a-9449-321463c2fc29n%40googlegroups.com.


--
--
Conor Artman

Yilin Huang

unread,
Feb 3, 2021, 2:16:54 PMFeb 3
to ProjectMesa
Hi Cornor,  thank you for your reply. The problem is not to construct an agent with unique_id, but to find back the agent reference with the information of its unique_id. I see there is an agent list in the Mesa scheduler. I was just wondering if there is an easier way than to go through the list or create a dict for that. After I posted my question, I did find an earlier thread that discussed this very issue though. The answer is: I do need to create my own dict to do that. Thanks for your answer anyway.

Tom Pike

unread,
Feb 3, 2021, 2:59:23 PMFeb 3
to Yilin Huang, ProjectMesa

Yilin: If I am understanding correctly you want to retrieve the agent by its unique_id, correct?

 

The agent scheduler in  mesa.time is an Ordered Dictionary. so you can retrive the agent object by calling ``` <model.scheduler>._agents[<unique_id>]```, that will return the agent object.  

 

Tom Pike

 

Sent from Mail for Windows 10

Yilin Huang

unread,
Feb 3, 2021, 3:10:45 PMFeb 3
to Tom Pike, ProjectMesa
Exactly what I needed. Thanks Tom!
Best,
Yilin
Reply all
Reply to author
Forward
0 new messages