0
votes

I'm starting to use Anylogic for a simulation class, and for this I need to model the following behaviour: there's a stream of agents that enter a FIFO queue, and then enter into a server (that I modeled with a delay block), one at a time. The agents have two states (call them A and B), and if an agent reaches the end of the queue in state A, it has to wait until it returns to state B to go into the service.

I think a wait block with capacity for one agent, between the queue and the delay block could potentially solve this situation. But I don't know how to make the wait block to free the agent as soon as it changes state.

Other methods are welcome. I just need the agent to be retained before the delay block as long as it is in the state A, but not any longer. Thanks in advance.

1

1 Answers

0
votes

Yes... a wait block with capacity 1 after your queue block is what I would do.

Now when your agent enters the state, on the entry action of that stateB you do the following:

if(currentBlock().equals(main.waitBlock) && main.service.size()==0){
    main.waitBlock.free(this); 
}

You will also need to do this in the "on enter" of the wait block:

if(agent.inState(agent.stateB) && service.size()==0){
    self.free(agent);
}

also, just in case, add a population of 0 of your agent type in main, to be able to use main. in your agent state code.