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