Ella
Ella

Reputation: 125

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

Upvotes: 1

Views: 646

Answers (2)

Emile Zankoul
Emile Zankoul

Reputation: 2213

Create a cyclic event that occurs every hour. Also add two datasets to your model: one named cumulativeArrivals, the other arrivals (of course feel free to name the datasets whatever makes sense to you). Finally add a variable of type int called count with initival value 0.

enter image description here

Then, in the event action field, write the following code:

cumulativeArrivals.add(enter.out.count());

if( count == 0 )
   arrivals.add(cumulativeArrivals.getY(count));
else
   arrivals.add(cumulativeArrivals.getY(count) - cumulativeArrivals.getY(count-1));

count++;

enter image description here

Finally, add a plot with the following settings: enter image description here

Upvotes: 2

Benjamin
Benjamin

Reputation: 12605

  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.

Upvotes: 2

Related Questions