0

我希望能够根据队列长度修改轨迹内的资源容量。

下面的(简化的)代码不起作用。- 当我尝试get_mon_resources(simStore)在函数内部调用时,代码崩溃并出现错误:

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

谢谢您的帮助。

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
4

1 回答 1

0

在此处查看与解决此问题相关的讨论:https ://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/simmer-devel/NgIikOpHpss

导致问题的原因是另一个包(lubridate)从“simmer”中屏蔽了对象,如下所示:

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

一旦我更换

 library(simmer); library(lubridate);

library(lubridate); library(simmer); 

问题消失了!

于 2017-06-30T16:39:14.597 回答