0

I'm trying to run a standard SIR agent-based model where agents transition from 'Susceptible' to 'Infected', and from 'Infected' to 'Recovered'. I'm now interested in calculating the instantaneous incidence, i.e. the number of agents who transition from 'Susceptible' to 'Infected' state at a given time t.

For example: On day 1 (model time), 2 agents transition from 'Susceptible' to 'Infected' On day 2 (model time), 5 agents transition from 'Susceptible' to 'Infected' On day 3 (model time), 7 agents transition from 'Susceptible' to 'Infected' . . .

I am able to get the total count of 'Infected' agents, but I'm interested in knowing this value of each time step. I'm looking to write a function that cumulatively adds up the number of new infections for each time step.

Any ideas on how one might do this in AnyLogic would be very helpful. Thanks.

user3qpu
  • 67
  • 1
  • 10

2 Answers2

0

I suggest you create a collection on Main col_Counter of type where the key is the day and the value is the number of infections. Then create a recurring event in the Agent called e_Counting starting at the model start and recurring every 24 hours. In the action write:

main.col_Counter.add(date(), v_countsToday);

v_countsToday=0;

Also create the v_countsToday as an integer-variable in the agent. Add +1 whenever an infection happens.

There are many other ways but this will work.

cheers

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • Thank you for your comment. It appears that I'm unable to choose the right type of collection. The only types of collection that allow a key and value to be entered are TreeMap and LinkedHashMap. Neither of them seem to accept the (Date, double) argument. Could you tell me how I could do this please? Thanks. – user3qpu Nov 10 '17 at 13:53
  • use a LinkedHashMap. Set the key and value type in the properties. And amend the code above to "main.col_Counter.put(date(), v_countsToday);". – Benjamin Nov 10 '17 at 19:26
0

Here is a screenshot, you need to select "Other" for the key to manually type the dimension "Date()": enter image description here

Benjamin
  • 10,603
  • 3
  • 16
  • 28