首页 > 解决方案 > How I can evaluate a condition on next time-step in anylogic?

问题描述

I am trying to write a code for one state to another state transition where the system will first store the initial model time and then will check a condition (used while loop). It will continue to run the loop until the condition is false and when the condition is false it will record the final model time. So, my main objective is to get the total time that while loop condition is true. The problem is, I don't know how to check the while loop every 1 time step, For example, I tried "wait (1);" in place of "???" section of the below code which is not correct. Can anyone please suggest how I can do this?

My transition code as below: ... ...

initialTime=time();

    while ((thisPed.inState(walking) && thisPed.fieldOfVision.contains(pedX, pedY)); 
    {
    ???
    }
    finalTime= time();
    exposureTime = finalTime - initialTime;

... ...

标签: anylogicagent-based-modeling

解决方案


you can't put while statements in a model that at the same time run with time steps... to do that you have many other ways..

For instance you can generate a transition that goes from that state to the same state (internally) and generate your code there every time step.

enter image description here

Another option is to use a conditional transition in the same way

BUt NOT a while loop


推荐阅读