Search code examples
anylogicagent-based-modeling

Looping through agents in a queue


I'm new to Anylogic and Java, so I apologize in advance if this is a beginner question. I have one agent type that enters a queue (for example, called queue_X). I would like to loop through all the agents in the queue and perform some check on a parameter (that governs the removal of the agent from the queue). There may not be any agents in the queue in some instances.

This loop is set up inside an event that executes every X minutes.

What is the syntax for looping through the agents?

Thanks in advance for any help you can provide. Cheers


Solution

  • Simplest way:

    for (int i=0; i< myQueue.size(); i++) {
        MyAgentType currentAgent = ((MyAgentType)myQueue.get(i));
    }
    

    This assumes there are only agents of type MyAgentType in your queue