Using programming language R or others (e.g. Python, Matlab, ...) to conduct the commented code describe in the pictures
Posted: Fri Jul 08, 2022 6:39 am
Using programming language R or others (e.g. Python, Matlab,...) to conduct the commented code describe in the pictures below.Screen capture as an answer is preferred
Thank you
1. In this project you'll simulate an M/M/1 queueing system. The quantities you'll work with are T = kth interarrival time, and You might also need and ak = kth customer's arrival time, Sk = kth customer's service time, dk = kth customer's service completion time. qk= kth customer's system time. Note that I have used standard mathematical sequence notation in the above definitions. In R, these would be T[k], a[k], etc. Wk= kth customer's queue time, 2. In this exercise you'll write an R. function qsim(n,A, µ) that generates a 2 x n matrix storing the following information: for k > 1. • The first row of the matrix should be a sequence T of n arrival times with rate parameter X. • The second row of the matrix should be a sequence S of n service times with rate parameter . With qsim written, the command times = qsim(10000, 2, 4) will store the 2 x 10,000 matrix in "times." The commands mean(times[1,]) and mean(times [2,]) will get you the sample mean interarrival and serivce times. If the numbers are close to .5 and .25 respectively, then your qsim is probably working correctly. 3. Rewrite qsim. The new version should generate the sequence T of n arrival times with rate parameter A. • the sequence S of n service times with rate parameter . • the sequence a of n arrival times. You can use the command cumsum for this. • the sequence d of n service-completion times. You can use a loop for this. Initialize the loop with d₁ = a₁ + S₁ (1) and use the recursion relation dk+1 =max(dk, ak+1) + Sk+1, (2)
4. Add another feature to qsim: In addition to the four items listed in part (3), have qsim generate the sequence w of total system times. This is trivial, since w= d.- a. Store a, d and w in a 3 x n matrix. The command times = qsim (10000, A, µ) stores the matrix in times. Test your work with the command mean(times[3,]). You should get something close to E(W) H- Just be sure to choose X <μ. 5. Add still another feature to qsim: Let M be the 3 x n matrix described in the previous paragraph. The last relevant time 7 for the simulated M/M/1 system is the service completion time of the nth customer T = M[2,n]. As detailed in class, you should use the seq and length functions to define the sequence t of sample times: t = {t₁, t₂,..., tu} where t = 2k. Next, use the sum function in a loop to define the sequence of system states state = {state[1], state[2], ..., state[L]}. Thus state[k] is the system state at time t = .2k. Test this latest version of qsim with the command systemstates = qsim (10,.3,.5). You will get a sequence of nonnegative integers representing the system states at the sampling times tk. 6. Add commands to qsim to generate a probability histogram for the system state. Use hist (state, ylim = c(0,1), breaks = c(0, seq(1, max(state), 1)), prob • axis (side = 2, at = .1*c (0:10)) • axis (side = c(0, max(state))) 7. Use the histogram generated by qsim (5000, .2, .4) to estimate the probabilities P{system state = 0} and P{system state < 1}. Are you close to Po and Po+ P₁ as predicted by the steady-state M/M/1 theory? = = 1, at = TRUE)
Thank you
1. In this project you'll simulate an M/M/1 queueing system. The quantities you'll work with are T = kth interarrival time, and You might also need and ak = kth customer's arrival time, Sk = kth customer's service time, dk = kth customer's service completion time. qk= kth customer's system time. Note that I have used standard mathematical sequence notation in the above definitions. In R, these would be T[k], a[k], etc. Wk= kth customer's queue time, 2. In this exercise you'll write an R. function qsim(n,A, µ) that generates a 2 x n matrix storing the following information: for k > 1. • The first row of the matrix should be a sequence T of n arrival times with rate parameter X. • The second row of the matrix should be a sequence S of n service times with rate parameter . With qsim written, the command times = qsim(10000, 2, 4) will store the 2 x 10,000 matrix in "times." The commands mean(times[1,]) and mean(times [2,]) will get you the sample mean interarrival and serivce times. If the numbers are close to .5 and .25 respectively, then your qsim is probably working correctly. 3. Rewrite qsim. The new version should generate the sequence T of n arrival times with rate parameter A. • the sequence S of n service times with rate parameter . • the sequence a of n arrival times. You can use the command cumsum for this. • the sequence d of n service-completion times. You can use a loop for this. Initialize the loop with d₁ = a₁ + S₁ (1) and use the recursion relation dk+1 =max(dk, ak+1) + Sk+1, (2)
4. Add another feature to qsim: In addition to the four items listed in part (3), have qsim generate the sequence w of total system times. This is trivial, since w= d.- a. Store a, d and w in a 3 x n matrix. The command times = qsim (10000, A, µ) stores the matrix in times. Test your work with the command mean(times[3,]). You should get something close to E(W) H- Just be sure to choose X <μ. 5. Add still another feature to qsim: Let M be the 3 x n matrix described in the previous paragraph. The last relevant time 7 for the simulated M/M/1 system is the service completion time of the nth customer T = M[2,n]. As detailed in class, you should use the seq and length functions to define the sequence t of sample times: t = {t₁, t₂,..., tu} where t = 2k. Next, use the sum function in a loop to define the sequence of system states state = {state[1], state[2], ..., state[L]}. Thus state[k] is the system state at time t = .2k. Test this latest version of qsim with the command systemstates = qsim (10,.3,.5). You will get a sequence of nonnegative integers representing the system states at the sampling times tk. 6. Add commands to qsim to generate a probability histogram for the system state. Use hist (state, ylim = c(0,1), breaks = c(0, seq(1, max(state), 1)), prob • axis (side = 2, at = .1*c (0:10)) • axis (side = c(0, max(state))) 7. Use the histogram generated by qsim (5000, .2, .4) to estimate the probabilities P{system state = 0} and P{system state < 1}. Are you close to Po and Po+ P₁ as predicted by the steady-state M/M/1 theory? = = 1, at = TRUE)