The following code in Anylogic should normally release 500 agents from wait block. Note that wait block has more than 500 agents thats how I am calling the function.
But for some reason wait.get(0) is always returning root.box(0). Box is my population. I am finding this to be very strange. Even when root.box(0) has left the wait block, wait.get(0) is always returning root.box(0).
for(int i=0; i<500; i++){
wait.free(wait.get(0));
traceln(wait.get(0));
}
I am using Material Handling Library. So wait block is placed after the store block. Anyone knows whats happening?
When you use java to tell AnyLogic to do something on the event calendar, the entire java will complete, and then AnyLogic will manage the agents on the blocks. That is, all 500 loops complete and then AnyLogic executes the 500 events of removing from the wait.
For your code, if you want to release 500 agents, you can do the following:
for(int i=0; i<500; i++){
// get the agent in the i position
Agent agent = wait.get( i );
// free the agent
wait.free(agent);
}
or, since java will go through the entire loop, you could also just do
for(int i=0; i<500; i++){
wait.free(wait.get(i)); // free the agent in the i position
}