-2

My question:

At an institute for experimental mathematics there is a computer that helps solve problems.

Problems arrive to the computer at a poisson process with intensity "Landa" per hour.

The time to solve each problem can be seen as a exponential distribution with parameter "mu".

In our world we have four different states. S = (0,1,2,3)

State 0 = 0 problems have arrived to the computer

State 1 = the computer is solving 1 question

State 2 = the computer is solving 1 question + 1 in queue.

State 3 = the computer is solving 1 question + 2 in queue.

If a question comes when we are in state 3, the sender gets an error message and tries again later. The institution has decided that maximum of 5 % of the senders should get this error message.

To decide who should have access to the computer, we are 3 different proposals.

  1. Only the professors are alowed to send questions ( Landa = 2, Mu = 10)
  2. Professors and students are alowed to send questions( Landa = 6, Mu = 10)
  3. Anyone is alowed to send questions( Landa =10, Mu = 10)

We should investigate what of the 3 proposals don't fill upp the computer more than 5% of the time.

I have two things i need help with

First thing: To Solve the question I've been given this structure of code(the code under). What i need help with is if someone can briefly explain to me the purpose of the following code paragraf where i have written "#?".

So what i really need help with is some1 to explain parts of the code.

Secound thing: In two places i have written "...", there i need help to fill in some code.

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
        }

        #?
        time_to_transition <- ...

        #? 
        if (...) {
            state_now <- state_now - 1
        } else {
            state_now <- state_now + 1
        }

        #?
        time_now <- time_now + time_to_transition 
        #?
        time <- c(time, time_now) 
        #?
        state <- c(state, state_now) #WHAT DOE THIS VECTOR CONSIST OF?
    }
    list(time = time, state = state)
}
PeterNiklas
  • 75
  • 1
  • 9
  • 1
    Whoa, this is quite the question. Can you please reduce to an [mcve] for ease in answering? – Stedy Jul 13 '16 at 17:34
  • 2
    You seem to have copy/pasted a problem statement. Do you understand the problem? Do you understand the goal of the `bd_process` function? At the end, it returns `tid` and `state`, but you have have a question mark on the updating of `state` and write "`#WHAT DOE THIS VECTOR CONSIST OF?`". Not understanding the return makes me think you don't understand the goal of the function – Gregor Thomas Jul 13 '16 at 17:39
  • 1
    Perhaps you could also explain what you do know. For example, you have question mark about the line `time_now <- time_now + time_to_transition `. This is a simple addition. It adds the current value of `time_now` to the current value of `time_to_transition` and calls the result `time_now`, hence updating the `time_now` variable. Is this the level of explanation you need? – Gregor Thomas Jul 13 '16 at 17:41
  • This code is not something i have written. It was given to me and I'm trying to understand the structure of it. What i di understand is: The first paragraf in the loop, states that when we are in state 3, no more can be placed in queue. The second paragraf in the loop says that when we are in state 0, no problems are being solved. And in any other state, they will be solved at a intensity of mu. I dont understand the code under this point. So Time_to_transition and down is something i don't understand. – PeterNiklas Jul 13 '16 at 18:34
  • At if (...) { state_now <- state_now - 1 } else { state_now <- state_now + 1 } my guess is that "..." should be changed to time_now == 0, or something like this? – PeterNiklas Jul 13 '16 at 18:37
  • @Gregor i don't know if u got a notification for that so ill try this – PeterNiklas Jul 13 '16 at 19:01
  • Maybe "time_to_transition <-" is to say that the questions are coming in a poison process? What do you guys think? – PeterNiklas Jul 13 '16 at 19:10

1 Answers1

0

The code appears to be written with an implicit assumption that the interarrival and service distributions are memoryless, i.e., either exponential or geometric. Without memorylessness it's invalid to turn off processing by setting the rates to zero.

With the memoryless property, you can figure out the time_to_transition as a superposition of the two Poisson processes, and determine whether it was an arrival or a departure by randomizing proportional to the ratio of one of the rates to the combined rate. It's also valid to zero one of the rates then because when you unzero it the elapsed time where the rate was zero doesn't matter due to the memoryless property.

pjs
  • 18,696
  • 4
  • 27
  • 56
  • Hello, pjs. I think that time_to_transition is the time to leave one state and that it can be seen as Exp(mu) + Exp(lambda). Is there anyway to code that?When i write it in i get "Exp" not found. – PeterNiklas Jul 17 '16 at 14:52
  • @PeterNiklas Assuming you mean exponentially distributed with rate mu when you write `Exp(mu)`, the next transition is not `Exp(mu) + Exp(lambda)`. It's at the smaller of the two -- `min(Exp(mu), Exp(lambda))`, which has distribution `Exp(mu + lambda)`. – pjs Jul 17 '16 at 16:57