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.
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.
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()
#> time name key value replication
#> 1 3 dummy0 my_key 123.0000000 1
#> 2 3 global_key 321.0000000 1
#> 3 3 dummy0 my_key 5.0000000 1
#> 4 3 dummy0 other_key 64.0000000 1
#> 5 3 dummy0 my_key 6.0000000 1
#> 6 3 dummy0 independent_key 0.8609154 1
#> 7 3 dummy0 dependent_key 0.0000000 1