1

I've have a Birth & Death process code problem. I have 4 states S = {0,1,2,3}

In state 0, there are no customers. In state 1, there is 1 customer being treated. In state 2, there is 1 customer being treated +1 in queue. In state 3, there is 1 customer being treated +2 in queue.

If more customers come than in state 3, they go away and come back later.

Lamba is the number of customers arriving per hour. Mu is the numer of customers being treated per hour.

Initially we start at in state 0.

For the moment I'm just trying to understand the code under. In the code I've written in Caps lock, were I need help.

If you need more info to understand the question, please write a comment.

bd_process <- function(lambda, mu, initial_state = 0, steps = 100) {
time_now <- 0
state_now <- initial_state
time <- 0
state <- initial_state

for (i in 1:steps) {


if (state_now == 3) {
lambda_now <- 0
}else {
  lambda_now <- lambda
}


if (state_now == 0) {
mu_now <- 0
}else {
mu_now <- mu
}


#? WHAT DOES TIME_TO_TRANSISTION DO? WHAT SHOULD BE INSTEAD OF "..."?
time_to_transition <- ...


 #? WHAT DOES THIS CODE DO? WHAT SHOULD BE INSTEAD OF "..."?
if (...) {
  state_now <- state_now - 1
} else {
  state_now <- state_now + 1
}


time_now <- time_now + time_to_transition #WHAT IS TIME_NOW?
time <- c(time, time_now) #WHAT DOES THIS VECTOR CONSIST OF?
state <- c(state, state_now) #WHAT DOE THIS VECTOR CONSIST OF?
}
list(tid = tid, state = state) }
IRTFM
  • 258,963
  • 21
  • 364
  • 487
PeterNiklas
  • 75
  • 1
  • 9
  • You need not just a number treated per hour but also a mathematical description of the distribution of times to complete treatment. Likewise for arrival times. Then you will be in a situation where you can model the queuing. Look up queuing theory. Since this does yet involve a coding issue but rather a conceptual difficulty, you should consider asking in CrossValidated.com. That's what my closevote is attempting to initiate, but you could also request moderator migration. – IRTFM Jul 12 '16 at 19:10
  • I do have values for landa & mu, however, i don't think u need them now since i just want to code the queuing system correctly first. Ill take a look at the website. – PeterNiklas Jul 12 '16 at 19:20
  • I found a fairly complete answer composed in R at that website as well as citations of an R package named `queueing`. Also search with [r] [queue] [simulation] brought up an earlier (unanswered) question from someone who had proceed further than you had in the sense of actaully using distributional assumption for arrival and service. – IRTFM Jul 12 '16 at 19:22

0 Answers0