Search code examples
plotanylogic

How to plot arrival rate per hour of agents in enter block?


In my Anylogic model I let agents (trucks) enter the process blocks of a terminal. I want to plot this "arrival rate" per each hour of the day (e.g., 100 trucks between 12:00-13:00 arrived at this terminal), for all hours of the day (24). How can I do this the simplest way?

enter image description here


Solution

    1. Create a dataset myDS that does not update itself. Make sure to untick "use time as horizontal value" (we will use the time but in hour time units)
    2. create an int variable counter
    3. create an event that cyclically triggers every hour.

    In the event code, write:

    myDS.add(time(HOUR), counter); // stores number of arrivals in the past hour, stored at the current model time
    counter = 0; // reset for next interval
    

    In the enter block's "on enter" code, update the counter every time an agent arrives, using counter++;

    Now you have a DS that stores how many agents arrived each hour. Plot that in a time plot and you are good to go.