Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I generate unique numerical IDs for agents created by three different sources in AnyLogic?

I have three sources that create agents and then flow into a queue. All three sources create different agents.
My idea is to assign an ID (numerical value of int) to each created agent in each source at "Actions – On before Arrival". The ID should be unique. So it should be prevented that the sources generate the same ID .
All ID coming from source 1,2,3 should be stored in the queue in a list after FIFO and output. To do this, I want to create a variable that can then store and output all the ID created.

Can someone help me and find a suitable code for the "source" which assigns an ID to each agent?

I have not managed to find a code that satisfies this property.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add a variable of type int named counter next to the sources. In each source’s "on at exit" code box, write:

counter++;
agent.set_p_MyID(counter);

this assumes all your agents created by the sources have a parameter of type int name p_MyID

With this universal counter, you will get unique ids.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading