Is is possible to plot resource usage by attribute in simmer? So for example in this simulation:
library(simmer)
library(simmer.plot)
workerCount <- 2
actualData <- data.frame(
time = c(1:10,1:5), priority = 1:3, service = rnorm(150, 50, 5)) %>%
dplyr::arrange(time)
actualData$gender<-floor(runif(150, min=1, max=3))
actualData
activityTraj <- trajectory() %>%
seize('worker') %>%
timeout_from_attribute("service") %>%
release('worker')
env <- simmer() %>%
add_resource('worker', workerCount, Inf, preemptive = TRUE) %>%
add_dataframe('worker_', activityTraj, actualData, mon=2, col_time="time", time="absolute", col_attributes=c("gender","service")) %>%
run()
plot(get_mon_attributes(env), keys="gender", metric="usage")
The plot generated shows gender over time but not resource usage. The documentation for plot.attributes says:
The S3 method for 'attributes' does not support any metric. It simply shows a stairstep graph of the values throughout the simulation for the keys provided (or all the collected attributes if no key is provided).
Is there any way currently to plot resource usage by attributes?
Thanks for any suggestions.
You could get the service and waiting times per resource from the arrival table with get_mon_arrivals(env, per_resource=TRUE)
. Then, get the name<->gender correspondence from the attributes table with get_mon_attributes(env)
, join the tables and, finally, reconstruct the server usage by gender using the time series. But that's a bit challenging. Doable, but it requires some work.
I would just increment/decrement some auxiliary global variables based on that attribute to keep the count for me.