AnyLogic variable for cumulative sum in system dynamics

318 Views Asked by At

Good morning, in a System Dynamics model created on AnyLogic, I would like to compute the cumulative sum of a flow of the previous 7 days. My purpose is to calculate the reproduction ratio of a disease starting from the infectious population at time t over the cumulative sum of the infectious in a fixed time interval. The formula is the following:

Formula

where:

  • I(t) = infectious population at time t --> I(t) is a flow in the model that changes a stock
  • I(t-s) = infectious population at time t-s
  • w(s) = gamma distribution
  • s represents the time interval of the previous 7 days

I have all the data but I am not able to calculate the sum of I(t-s).

Thanks.

1

There are 1 best solutions below

2
On

You have to do this manually. Create a variable mySum of type double. Then, add a cyclic event that regularly adds to it from the stock (something like myVar += myStock).

You may need to use an additional variable that stores the temporary stock value from the last time you added, so you only add what was "new" since the last cycle.

In short: use a cyclic event to "approximate" your integral.