Search code examples
anylogic

How to execute a function involving agent within a process block in AnyLogic


I'm using a code in the On Enter field of a Delay block and I've noticed the code is executed only once when the agent enter the block (as expected). However, as this code has a condition that agents should meet before proceeding to the next block, whenever the condition is not met (on Enter), agent get stuck in the block. I need this code to be executed daily rather than just once and, of course, only for the agent in that block, rather than to the entire population.

Any guesses?

Many thanks


Solution

  • Another option: Use a Dynamic Event MyDE in your Agent.

    On entering the Delay block, you trigger the DE using create_MyDE(0, SECOND);.

    In the DE, you check your condition:

    if (myConditionIsMet) {
        main.delayBlock.remove(this); // free this agent from the delay block
    } else {
        create_MyDE(24, HOUR); // check again in 24 hrs
    }
    

    The agent will stay in the Delay block until the condition is true, which is checked every 24 hrs (but not thereafter)