【问题标题】:Simmer Get_attribute | there is no arrival running errorSimmer Get_attribute |没有到达运行错误
【发布时间】:2017-11-17 18:33:34
【问题描述】:

首先,这个simmer_vignette 和这个链接advanced_simmer_usage 似乎表明错误源于“get_name、get_attribute 和 get_prioritization 是在轨迹内部使用的;否则将不会到达运行,这些函数将引发错误” 一个最小的可行示例:

  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(prob = get_attribute(env, "independent_key"))

不用说,这也会引发错误“get_attribute_(private$sim_obj, key, global) 中的错误:没有到达运行”。
有谁知道这可能是什么原因?我觉得唯一的选择是上面的解释“get_attribute 是为了在轨迹内使用”——但我觉得我正在这样做。

已经谢谢了!

【问题讨论】:

    标签: r simulation event-simulation


    【解决方案1】:

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

    【讨论】:

    • 没错。第一个版本立即调用该函数,因此它失败了。相反,第二个版本定义了一个在模拟过程中被调用的匿名函数。
    • @IñakiÚcar 谢谢你的解释,这是有道理的
    猜你喜欢
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 2013-07-25
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多