Search code examples
variablesconditional-statementsprobabilityanylogicagent

Anylogic: Why is my SelectOutput with agent variable value condition not working?


I have a SelectOutput block in my Anylogic model that tests the variable probabilityhub of the agent going through the process blocks. If it is higher than 0.5, it is false and the agent should go down.

enter image description here

The variable probabilityhub is given in the TOD delay block like agent.probabilityhub = some formula. I checked to see if the variable is given to the agents correctly, by writing them in a dataset at the exit of delay block TOD (like dataset.add(agent.othervariable,agent.probabilityhub);) and as you can see in the dataset, it works and the probabilityhub sometimes is higher than 0.5. However, as you also can see in the figure below, the SelectOutput is always true and none of the agents are going down... Does anyone know why this could be the case?

enter image description here


Solution

  • the action "on exit" of the delay block occurs AFTER the selectOutput condition calculation, so if you change the value of your probability on the on exit action, it's too late... This is counterintuitive in anylogic but things happen in the reverse order of the flow... which is weird, but it is like that

    So calculate it in the "on at exit" action instead, and everything will work