Skip to contents

Define a new resource in a simulation environment. Resources are conceived with queuing systems in mind, and therefore they comprise two internal self-managed parts: a server, which is the active part, with a specified capacity that can be seized and released (see seize); and a priority queue of a certain size, in which arrivals may wait for the server to be available.


add_resource(.env, name, capacity = 1, queue_size = Inf, mon = TRUE,
  preemptive = FALSE, preempt_order = c("fifo", "lifo"),
  queue_size_strict = FALSE, queue_priority = c(0, Inf))



the simulation environment.


the name of the resource. If several names are provided, several resources will be defined with the same parameters.


the capacity of the server, either an integer or a schedule, so that the value may change during the simulation.


the size of the queue, either an integer or a schedule, so that the value may change during the simulation.


whether the simulator must monitor this resource or not.


whether arrivals in the server can be preempted or not based on seize priorities.


if preemptive=TRUE and several arrivals are preempted, this parameter defines which arrival should be preempted first. Either fifo (First In First Out: older preemptible tasks are preempted first) or lifo (Last In First Out: newer preemptible tasks are preempted first).


whether the queue_size is a hard limit (see details).


the priority range required to be able to access the queue if there is no room in the server (if a single value is provided, it is treated as the minimum priority). By default, all arrivals can be enqueued.


Returns the simulation environment.


An entity trying to seize a resource (see seize) may 1) access the server straightaway if there is enough capacity, 2) wait in the queue if there is no room in the server but there is room in the queue, or 3) rejected if there is no room in the queue either.

There are two special situations regarding queue management: 1) the queue_size is shrinked below the actual number of items waiting, and 2) preemption occurs, and an item previously in the server goes to the queue. By default in both cases, the excess of items in the queue is allowed. However, with queue_size_strict=TRUE, the maximum queue_size is guaranteed, and thus some entities will be rejected (dropped) by the resource.

Whenever an arrival is rejected (due to a server drop or a queue drop), it will set the finished flag to FALSE in the output of get_mon_arrivals. Unfinished arrivals can be handled with a drop-out trajectory that can be set using the handle_unfinished activity.

See also

Convenience functions: schedule.