RenegeIn 其他弹道R(文火包)

RenegeIn other trajectory R (simmer package)

我是 R 的新手

我正在尝试用 simmer 模拟排队。

我想启用从 "Typhon" 到 "Tornado" 的 Renege。但是我的代码创建了一个 "Tornado" 的新轨迹,而我需要的只是一个 "Torando" 轨迹。 (见下图)

我的问题是如何启用Renge到现有轨迹? (在我的例子中是从 "Typhon" 到 "Tornado")

这是我的代码和情节:

##----------------------------------------- 1.  all functions ------------------------------------------------

## add service 
addService<- function  (path,sname,timeDist){
  updatedPath <- seize(path, resource = sname, amount = 1)%>%
    timeout(timeDist) %>%
    release(resource = sname,  amount = 1)

  return(updatedPath)
}
##abound function
addServiceRenge<- function  (trajectory,sname,timeDist,renegDist, continueTo){
  updatedPath <- renege_in(trajectory,renegDist,out= continueTo %>% log_("I left angry!") )%>%
    seize(resource = sname, amount = 1)%>%
    renege_abort()%>%
    timeout(timeDist) %>%
    release(resource = sname, amount = 1)

  return(updatedPath)
}

##----------------------------------------- 2.  all simulation parameters ------------------------------------------------

set.seed(654)
simulationTime <- 7*60
openTime<-rnorm(1,17,3)
gate_schedule<-schedule(timetable = c(0, openTime), values = c(0, Inf), period = Inf)

##----------------------------------------- 3.  Init Simulation and add all resources  ------------------------------------------------

bravePool<-simmer("brave pool")%>%
  add_resource("DoorMan",capacity=gate_schedule,queue_size=Inf)%>%
  add_resource(name="Staris",capacity=1,queue_size=Inf)%>%
  add_resource(name="Tornado",capacity=1,queue_size=Inf)%>%
  add_resource(name="Typhon",capacity=1,queue_size=Inf)%>%
  add_resource(name="Hurrican",capacity=1,queue_size=Inf)

##----------------------------------------- 4.  All trajectories, start from main trajectory and add sub-trajectories ABOVE IT it . ------------------------------------------------

swimmerToHurrican <- trajectory("to hurrican")%>%
  addService(sname = "Hurrican", timeDist = function() rexp(1,0.25))

swimmerToTornado <- trajectory("to tornado")%>%
  addService(sname = "Tornado", timeDist = function() dtriangle(1, min = 0.1, max = 0.5, mode = 0.5) )

swimmerToTyphon <- trajectory("to typhon")%>%
  addServiceRenge(sname = "Typhon", timeDist = function() rnorm(1,3,1), renegDist = function() runif(1,2,4), continueTo = swimmerToTornado)

swimmer<-trajectory("swimmer's path") %>%
  addService(sname = "DoorMan", timeDist = openTime)%>%
  addService(sname = "Staris", timeDist = function() runif(1,3.5,7.5))%>%
  branch(option=function() rdiscrete (1, c(0.4,0.061,0.364,0.175),c(0,1,2,3)) ,continue= c(FALSE,FALSE,FALSE),swimmerToTornado,swimmerToTyphon,swimmerToHurrican)

##----------------------------------------- 5.  All Generators, ALWAYS LAST. ------------------------------------------------

bravePool%>%
  add_generator(name="swimmers",trajectory=swimmer,distribution=function() rexp(1,3.5))

##----------------------------------------- 6.  reset, run, plots, outputs ------------------------------------------------
reset(bravePool)%>%run(until=simulationTime)

poolData<-get_mon_arrivals(bravePool, per_resource = T)
plot(swimmer)

您的代码没有问题,这是预期的。在内部,simmer 会精确复制轨迹(以避免出现问题,例如,如果您删除原始轨迹),但不要担心,它应该会按预期工作。