Simulation of a $ M/M/1/3$ queuing system (probability that it will become full in first $n$ time units).

51 Views Asked by At

I am trying to simulate the probability that an $M/M/1/3$ system will get full during its first n time units, meaning arrival and service times are exponential and here they are exp with mean $1.$

I also know that $X=0$ in the beginning.

My approach strategy is to just simulate say, $10000$ times and just use the amount of times that the system became full/(amount of repetitions).

Code:

                succ=0;
                sumsucc=1;
                X=0;
                reps=10000;

                for i =1:reps
                    T=0; %We start in the beginning, time is zero
                    X=0; %The queue starts out empty 
                    while T<=3 
                        if X==0 %if no customers, a customers arrives a exp(1) time later!
                            T=exprnd(1);
                            X=1;
                            continue %moves on to next iteration of loop
                        end
                        if X==1
                            rand1=exprnd(1);rand2=exprnd(1);
                            if rand1<rand2
                                X=0; T=T+rand1;
                            else
                                X=2; T=T+rand2;
                            end
                            continue
                        end
                        if X==2 %if there is 1 or 2 in system, competition between to random exp begins, rand 1 is service time, rand 2 is arrival time. First wins moves on to correpsonding place 
                            rand1=exprnd(1);rand2=exprnd(1);
                            if rand1<rand2
                                X=1; T=T+rand1;
                            else
                                X=3; T=T+rand2;
                            end

                            continue
                        end
                        if X==3 %if three, moves down and 1 successful event is added to "sumsucc"
                                sumsucc=sumsucc+1;
                                T=T+exprnd(1);
                                X=2;
                                break
                        end 
                    end
                end
     sumsucc/reps %should give me right answer.

Now, the expected answer is $0.268.$ Something is wrong.