Search code examples
anylogic

Update size of blocks from process modeling library during model run


I have a simple model I have built using the process modeling library in AnyLogic. Entities sit in the first delay block for the specified amount of time before passing to the next. See image.

enter image description here

When the size() of the first delay block exceeds 90 entities I would like to update the number of entities in both blocks by -10 and +10 respectively. Essentially, I want to push 10 from the first to the second.

This would replicate a real life process of a person deciding 10 entities don't need to wait in the first delay and are fine to skip to the next.

I have no problem with setting up an event which triggers when the size hits 90.

I know that I could use a source block to generate the 10 into the second block, but I couldn't find a way to push entities into a sink.

I also tried (as a bit of a longshot) using Block1.size() = Block1.size()+10 - this doesn't make the compiler very happy.

I found this documentation re adding or removing agents from a population (https://anylogic.help/anylogic/agentbased/dynamic-creation-and-destruction.html) but I don't require any agents with custom parameters so for simplicity I would like to keep working in the Main and would rather not create a population of agents.

Is there a way to update the sizes of blocks as I have specified?


Solution

  • if(Block1.size()>90){
        List <Agent> agentsInDelay=findAll(Block1,a->true).subList(0,10);
        for(Agent a : agentsInDelay){
            Block1.stopDelay(a);
        }
    }