慢炖 Get_attribute |没有到达 运行 错误

Simmer Get_attribute | there is no arrival running error

首先,这个 simmer_vignette and this linkadvanced_simmer_usage 似乎表明错误源于 "get_name, get_attribute and get_prioritization are meant to be used inside a trajectory; otherwise, there will be no arrival running and these functions will throw an error" 一个最小的可行示例:

  patient_traj <- trajectory(name = "patient_trajectory") %>%
  set_attribute("my_key", 123) %>%
  timeout(5) %>%
  set_attribute("my_key", function() get_attribute(env, "my_key") + 1) %>%
  timeout(5) %>%
  set_attribute("dependent_key", function() ifelse(get_attribute(env, "my_key")<=123, 1, 0)) %>%
  timeout(5) %>%
  set_attribute("independent_key", function() runif(1))

env<- simmer() %>%
  add_generator("patient", patient_traj, at(0), mon = 2)
env %>% run()
#> simmer environment: anonymous | now: 15 | next: 
#> { Generator: patient | monitored: 2 | n_generated: 1 }

get_mon_attributes(env)
#>   time     name             key       value replication
#> 1    0 patient0          my_key 123.0000000           1
#> 2    5 patient0          my_key 124.0000000           1
#> 3   10 patient0   dependent_key   0.0000000           1
#> 4   15 patient0 independent_key   0.9234335           1

现在它可以正常工作了,当我尝试以任何其他方式调用 get_attribute() 时,问题就开始了。在轨迹定义的最后 set_attribute() 之后添加这一行:

log_(get_attribute(env, "independent_key"))

抛出上述错误。 我真正想做的是调用 "leave" 函数并将其作为概率赋予属性。我在轨迹上还是这样做的。

leave(prob = get_attribute(env, "independent_key"))

不用说,这也抛出错误"Error in get_attribute_(private$sim_obj, key, global) : there is no arrival running"。
有谁知道这可能是什么原因?我觉得唯一的选择是上面的解释 "get_attribute is meant to be used inside a trajectory" - 但我觉得我正在这样做。

已经谢谢了!

好吧,我很不好意思这么说,但问题很容易解决。好像问题是直接访问属性。
所以 log_(get_attribute(env, "independent_key")) 不起作用,但 log_(function() get_attribute(env, "independent_key")) 起作用。
仅此而已。
如果有人能解释为什么只需要这样做,我将不胜感激。