'Anylogic: Time depending stock in-flow with table functions

I would like to simulate a stock (array with six different dimensions) and its changes over the years in Anylogic. The initial values of the stock are given as well as the changes over the years (Excel table format). I think the values of the stock changes can't be describes by a constant mathematical function. So, they need to be implemented in the model as a table.

My approach was to create the stock and also the in-flow as an array with the six dimensions. I entered the initial values in the stock (inital values of stock). After that, I created six table functions with the number of the year as the argument and the change value of the stock in this year in the value column (example of a table funcion). To get the particular in-flow for the current simulation year, I entered the table function in the in-flow and set a variable as an argument (inflow of the stock). For the variable I entered a function, which I found on the Anylogic help website. It is the following: int getYear(Date date) (current year variable).

So as my understanding is right, this variable should give out the current year of the simulation as an integer. Using this value as a argument for the table function, I was thinking the model should work, but it seams that there is a problem the variable for the current year. I hope this was understandable. If not, please don't hesitate to ask.

Do you have any idea what could be the mistake or what I can do better to create a working model?

Thank you very much for your help.

Have a nice day and stay save David



Solution 1:[1]

I've been looking for an answer to the same situation as yours, but wasn't able to find the clear guide for it.

In my case, I added an 'event' variable from the agent-based simulation palette with Trigger type == 'Timeout', Mode == 'Cyclic', and both First occurrence and recurrence time as 1 (in 'years' in your case).

Then, try to set actions for the event variable as what you intended:

Veraenderung_Lkw_Flotte [Nicht_Autom] = Veraenderung Nicht Autom pro Jahr(time());
Veraenderung_Lkw_Flotte [AF_Stufe_1] = Veraenderung Stufe 1 pro Jahr(time());
Veraenderung_Lkw_Flotte [AF_Stufe_2] = Veraenderung Stufe 2 pro Jahr(time());

Here, the time() returns the current model time. You may need to use different specification depending on your time specification.

Hope you find it helpful.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P