anylogic

How to get remaining time of delay of "Delay" block in Anylogic


I'm sorry in advance, I'm new to Anylogic and just learn how to use it. I can't use any method of getting time (getRemainingTime(), getDelayTime(), getElapsedTime()) for "Delay" block to use it in my model. "Delay" block has capicity=1 and I need to know time of every agent which gets there.

I tried to use default methods, but if i dont specify agent, i get "Method getRemainingtime() is not specified for type Delay". And if i specify agent, i get "'Detail' cannot be resolved to a variable" (Detail is my agent's name). I also tried to put agent in getRemainingtime() method by using method get(0): Delay.getRemainingtime(Delay.get(0)), but it doesn't work as well. I feel like I'm doing something wrong, but I can't understand what exactly.


Solution

  • You need to use the function correctly.

    As per the help, you can call getRemainingTime(Agent agent)

    But you need to specify the agent you want the remaining time for, your Delay block could have 100s of agents all awaiting their individual delay.

    So to get the 1st agent's delay of all the agents in a Delay block, you can call myDelayBlock.getRemainingTime(myDelayBlock.get(0))

    BUT: This assumes the delay block has an agent in it, which may not be the case when you call this.

    So to check this, you could first check with an if-statement like

    if (myDelayBlock.size()>0) {
        double delayTimeFound = myDelayBlock.getRemainingTime(myDelayBlock.get(0));
    } else {
        // do something else
    }
    

    PS: Also start learning the difference between agent types (MyAgent) and agent instances (myAgent), this is very important going forward