2

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."

Telso
  • 131
  • 8
  • Are the agents in the populations of the same agent type or different agent types? e.g. do you have an agent called `Rectangle` and you simply created two populations of the same agent type? – Jaco-Ben Vosloo Jul 04 '21 at 07:02
  • No the agents are distinct. So I made one agent type for red and one for blue. – Telso Jul 05 '21 at 10:04

1 Answers1

1

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

Benjamin
  • 10,603
  • 3
  • 16
  • 28