0

I want to be able to modify the resource capacity inside trajectory as a function of queue length.

The following (simplified) code below does not work. - When I try to call get_mon_resources(simStore) inside the function, the code crashes with the error:

Error in run_(private$sim_obj, until) : 
   Expecting a single value: [extent=0].

Thank you for your help.

simStore <- simmer()

fUpdateNumberOfCashiers <- function() {
  dtLastRes <- simStore %>% get_mon_resources  %>% tail(1) 
  nCapacityNow <- dtLastRes$capacity # same result with get_capacity(simStore),
  nQueueNow <- dtLastRes$queue       # same result with get_queue_count(simStore)  
  print(dtLastRes)                  # prints empty data-frame !
  return (5)  # crashes here ! (eventually 5 will be replaced with more meaningful formula
}

trajClient <- trajectory("Client's path") %>%    
  log_("Arrived to cashier") %>%
  set_capacity("Cashier", value = fUpdateNumberOfCashiers ) %>%
  seize("Cashier") %>%
  timeout(function() {rexp(1, 30)}) %>%    # One Cashier processes 30 clients / hour
  release("Cashier") %>% 
  log_(function(attr) { sprintf("In total spent %.2f", now(simStore) - attr["start_time"])})

simStore <- simmer("Store") %>% 
  add_resource("Cashier", 1) %>% 
  add_generator("Store Clients", trajClient,  function() {rexp(1, 120)}) %>% # 120 clients / hour
  run(until=nHoursObserved <- 1) ; simStore
IVIM
  • 2,167
  • 1
  • 15
  • 41

1 Answers1

0

See the discussion related to troubleshooting this problem here: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/simmer-devel/NgIikOpHpss

What causes the problem is that the other package (lubridate) masks objects from "simmer", as written seen below:

 Attaching package: ‘lubridate’
 The following objects are masked from ‘package:simmer’:
       now, rollback

Once I replaced

 library(simmer); library(lubridate);

with

library(lubridate); library(simmer); 

The problem disappeared!

IVIM
  • 2,167
  • 1
  • 15
  • 41