0

我是 R 的新手。

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

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

我的问题是如何使 Renge 进入现有轨迹?(在我的情况下是从“台风”到“龙卷风”)

这是我的代码和情节:

##----------------------------------------- 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)

阴谋

4

1 回答 1

1

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

于 2019-11-20T16:28:14.790 回答