Search code examples
anylogic

How to loop through the agents which are batched together at any point?


I am having a batching and un batching logic in my simulation model. I am collecting statistics on agent population which in my case is "MyAgent". But looks like it is ignoring the agents which are in Batch State. How can I get the agent's properties which are batched ? I want to loop through Batch to get which agents are batched at any point in time.

-Denter image description here


Solution

  • To access the agents inside a batch, you can use contents(). Add a custom population for the batches (and add the new batches to it - see image below), let's say you call it batchTypes, then to loop through the batched agents, you write the following:

    for( BatchType b : batchTypes) {
      for(int i = 0 ; i < b.contents().size() ; i++) {
        b.contents().get(i);
      }
    }
    

    enter image description here