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 get the last agent which was inside delay block in AnyLogic?

I would like to get the the agent which has just left the delay-block. I do not want to use on at exit if it is not necessary. So basically I want to use on exit and it gives back the agent which just left.
So for example the console says: "The agent that just left is ….", given that there is a System.out….. in the on exit.

I do not have a good idea sadly.

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 :

  1. Create a variable lastAgentLeft of the type that your agents actually are (assume MyAgent here)
  2. in the Delay‘s "on at exit" code box, write lastAgentLeft = agent;

That’s it. Now you can access the last agent always (by accessing that variable). Just make sure to test if any agent has actually left, for example by testing if (lastAgentLeft != null) (or fold that into a getter function)

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