Indentifying different agents in the same queue

Viewed 63

This is the problem:

I have two agent populations; "Blue rectangles" and "Red rectangles". Both of these agents go into the same queue. However it is a little hard to know how many red and blue rectangles are in the queue at an arbitraty time T.

Are there some functions/techniques to fetch this?

Would like to e.g. print in the console: "There are N blue rectangles and M red rectangles in the queue."

1 Answers

Sure, you can loop across all agents in your queue and check each by its agent type (assuming that blue and red agents are actually different agent types):

for (int i=0; i<myQueue.size(); i++) {
    if (myQueue.get(i) instanceof AgentTypeBlue) {
        // do whatever you want to count blue agents
    } else if (myQueue.get(i) instanceof AgentTypeRed) {
        // do whatever you want to count red agents
    }
}

Alternatively, just use the Queues "on enter" and "on exit" code boxes to count whenever a blue or red agent enters & leaves (using a variable countRed/countBlue`) as below: enter image description here

Related