How can I get the last agent which was inside delay block in AnyLogic?

Advertisements

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.

>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)

Leave a ReplyCancel reply