View source: R/monitor-methods.R
monitor | R Documentation |
Methods for creating monitor
objects for simulation environments.
monitor(name, xptr, get_arrivals, get_attributes, get_resources,
handlers = NULL, finalizer = NULL)
monitor_mem()
monitor_delim(path = tempdir(), keep = FALSE, sep = " ", ext = ".txt",
reader = read.delim, args = list(stringsAsFactors = FALSE))
monitor_csv(path = tempdir(), keep = FALSE, reader = read.csv,
args = list(stringsAsFactors = FALSE))
name |
an identifier to show when printed. |
xptr |
an external pointer pointing to a C++ object derived from the
abstract class simmer::Monitor. See C++ API for further details and, in
particular, the |
get_arrivals |
a function to retrieve the arrivals tables. It must accept
the |
get_attributes |
a function to retrieve the attributes table. It must accept
the |
get_resources |
a function to retrieve the resources table. It must accept
the |
handlers |
an optional list of handlers that will be stored in a slot of
the same name. For example, |
finalizer |
an optional one-argument function to be called when the
object is destroyed. For example, |
path |
directory where files will be created (must exist). |
keep |
whether to keep files on exit. By default, files are removed. |
sep |
separator character. |
ext |
file extension to use. |
reader |
function that will be used to read the files. |
args |
a list of further arguments for |
The monitor
method is a generic function to instantiate a
monitor
object. It should not be used in general unless you want to
extend simmer
with a custom monitor.
The in-memory monitor is enabled by default (memory_mem
),
and it should the fastest.
For large simulations, or if the RAM footprint is an issue, you may
consider monitoring to disk. To that end, monitor_delim
stores the values
in flat delimited files. The usual get_mon_*
methods retrieve
data frames from such files using the reader
provided. By default,
read.delim
is used, but you may consider using faster
alternatives from other packages. It is also possible to keep
the
files in a custom directory to read and post-process them in a separate
workflow.
monitor_csv
is a special case of monitor_delim
with
sep=","
and ext=".csv"
.
A monitor
object.
mon <- monitor_csv()
mon
env <- simmer(mon=mon) %>%
add_generator("dummy", trajectory() %>% timeout(1), function() 1) %>%
run(10)
env
read.csv(mon$handlers$arrivals) # direct access
get_mon_arrivals(env) # adds the "replication" column
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.