0

In Anylogic, If I have a 6000 agents in X population..How can I choose 2000 form this population to do a specific task ??

Thank you.

Rawand Smadi
  • 9
  • 1
  • 5

1 Answers1

1

If it is ok that you always select the same 2000 agents then this would work:

int i=0;
ArrayList<Agent> subsetOfAgents = new ArrayList<Agent>(2000);
for(Agent a : population)
{
   if(i >= 2000) break;
   subsetOfAgents.add(a);
   i++;
}

Your 2000 agents are then available in subsetOfAgents.

T_D
  • 1,688
  • 1
  • 17
  • 28
  • Thank you for your reply. But actually I don't need to add the same 2000 agents. I have a state chart and in every state I need to add agents based on specific criteria..@T_D – Rawand Smadi Jul 31 '17 at 21:20
  • Then check for the criteria in the loop like: if(a.criteria > 5) subsetOfAgents.add(a) – T_D Aug 01 '17 at 10:10