set_attribute: Set Attributes

View source: R/trajectory-activities.R

set_attributeR Documentation

Set Attributes

Description

Activity for modifying attributes. Attributes defined with set_attribute are per arrival, meaning that each arrival has its own set of attributes, not visible by any other one. On the other hand, attributes defined with set_global are shared by all the arrivals in the simulation.

Usage

set_attribute(.trj, keys, values, mod = c(NA, "+", "*"), init = 0, ...,
  tag)

set_global(.trj, keys, values, mod = c(NA, "+", "*"), init = 0, ..., tag)

Arguments

.trj

the trajectory object.

keys

the attribute name(s), or a callable object (a function) which must return attribute name(s).

values

numeric value(s) to set, or a callable object (a function) which must return numeric value(s).

mod

if set, values modify the attributes rather than substituting them.

init

initial value, applied if mod is set and the attribute was not previously initialised. Useful for counters or indexes.

...

unused.

tag

activity tag name to perform named rollbacks (see rollback) or just to better identify your activities.

Details

Attribute monitoring is disabled by default. To enable it, set mon=2 in the corresponding source (see, e.g., add_generator). Then, the evolution of the attributes during the simulation can be retrieved with get_mon_attributes. Global attributes are reported as unnamed key/value pairs.

Value

Returns the trajectory object.

See Also

get_attribute, get_global, timeout_from_attribute, timeout_from_global

Examples

env <- simmer()

traj <- trajectory() %>%

  # simple assignment
  set_attribute("my_key", 123) %>%
  set_global("global_key", 321) %>%

  # more than one assignment at once
  set_attribute(c("my_key", "other_key"), c(5, 64)) %>%

  # increment
  set_attribute("my_key", 1, mod="+") %>%

  # assignment using a function
  set_attribute("independent_key", function() runif(1)) %>%

  # assignment dependent on another attribute
  set_attribute("dependent_key", function()
    ifelse(get_attribute(env, "my_key") <= 0.5, 1, 0))

env %>%
  add_generator("dummy", traj, at(3), mon=2) %>%
  run() %>%
  get_mon_attributes()


simmer documentation built on Aug. 22, 2023, 5:09 p.m.