Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

RenegeIn other trajectory R (simmer package)

$
0
0

I'm new in R.

I'm trying to simulate queueing with simmer.

I want to enable Renege from "Typhon" to "Tornado". BUT my code creates a new trajectory to "Tornado" and what I need is just one "Torando" trajectory. (see picture below).

My question is how to enable Renge to an existing trajectory? (in my case is from "Typhon" to "Tornado")

This is my code and Plot :

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

plot


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>