View source: R/trajectory-activities.R
set_attribute | R Documentation |
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.
set_attribute(.trj, keys, values, mod = c(NA, "+", "*"), init = 0, ...,
tag)
set_global(.trj, keys, values, mod = c(NA, "+", "*"), init = 0, ..., tag)
.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, |
init |
initial value, applied if |
... |
unused. |
tag |
activity tag name to perform named rollbacks (see
|
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.
Returns the trajectory object.
get_attribute
, get_global
,
timeout_from_attribute
, timeout_from_global
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.