Anylogic: I've assigned a statistic value to a variable, but it only return 0

I have assigned a statistics value to the variable waiting_units using jeepneys.Waiting_Units_MDJ(). jeepneys is the population, and Waiting_Units() is the statistics. When simulated, it only returns 0 and not the statistics value.

It only shows the right statistic value if I add an event with an action waiting_units = jeepneys.Waiting_Units_MDJ(); to assign the value.

Is there a right way so I can assign the statistics value to a variable without using an event? I need the variable to continuously have the current value of the statistic.

I appreciate any help you can provide.

>Solution :

The Waiting_Units() statistic is a function (hence the brackets). By design, it is never actually calculated unless you call it. This is to avoid accidentally slowing your model.

It is your responsibility to call the function/statistic when you need it.

If you want to avoid using an event, you can also replace the statistic function with an Output object computing the same thing whenever you want:
enter image description here

Note that the code in the "Value" field depends on the setup of your current statistic.

Leave a Reply