7.3 The Simulation Enviroment

The simulation environment manages resources and sources, and controls the simulation execution. The simmer() method instantiates the object, after which resources and sources can be appended using the %>% operator:

env <- simmer() %>% 
  add_resource("res_name", 1) %>%
  add_generator("arrival", traj0, function() 25) %>%
  print()
## simmer environment: anonymous | now: 0 | next: 0
## { Monitor: in memory }
## { Resource: res_name | monitored: TRUE | server status: 0(1) | queue status: 0(Inf) }
## { Source: arrival | monitored: 1 | n_generated: 0 }

Then, the simulation can be executed, or run(), until a stop time:

env %>% run(until = 30)
## 25: arrival0: Entering the trajectory
## simmer environment: anonymous | now: 30 | next: 35
## { Monitor: in memory }
## { Resource: res_name | monitored: TRUE | server status: 0(1) | queue status: 0(Inf) }
## { Source: arrival | monitored: 1 | n_generated: 2 }

There are a number of methods for extracting information, such as the simulation time (now()), future scheduled events (peek()), and getters for obtaining resources’ and sources’ parameters (capacity, queue size, server count and queue count; number of arrivals generated so far). There are also several setters available for resources and sources (capacity, queue size; trajectory, distribution).

  • Resources: A simmer resource comprises two internal self-managed parts: a server and a priority queue. Three main parameters define a resource: name of the resource, capacity of the server and queue_size (0 means no queue). Resources are monitored, non-preemptive and assumes a first-in-first-out (FIFO) policy by default.

  • Sources: Three main parameters define a source: a name_prefix for each generated arrival, a trajectory to attach them to and a source of inter-arrival times. There are two kinds of source: generators and data sources. A generator (add_generator method) is a dynamic source that draws inter-arrival times from a user-provided function. The add_dataframe method allows the user to set up a data source which draws arrivals from a provided data frame.