Markov Chain Chap 9 - 20
Purpose
Queueing System
> trmatrix <- function(n, p, r) { + p_l <- r * (1 - p) + p_r <- p * (1 - r) + p_0 <- r * p + (1 - p) * (1 - r) + Q <- matrix(data = 0, nrow = n, ncol = n) + diag(Q) <- rep(p_0, n) + for (i in 1:(n - 1)) Q[i, (i + 1)] <- p_r + for (i in 2:n) Q[i, (i - 1)] <- p_l + Q[1, 1] <- 1 - p + Q[1, 2] <- p + Q[n, n] <- 1 - r + Q[n, (n - 1)] <- r + return(Q) + } > n <- 20 > p <- 0.6 > r <- 0.3 > Q1 <- trmatrix(n, p, r) > coefs <- t(Q1) - diag(n) > wts1 <- solve(rbind(c(rep(1, n)), coefs)[1:n, ], c(1, rep(0, + (n - 1)))) > s1 <- p/r > wts1 <- as.data.frame(wts1) > p <- 0.3 > r <- 0.6 > Q1 <- trmatrix(n, p, r) > coefs <- t(Q1) - diag(n) > wts2 <- solve(rbind(c(rep(1, n)), coefs)[1:n, ], c(1, rep(0, + (n - 1)))) > s2 <- p/r > wts2 <- as.data.frame(wts2) > p <- 0.5 > r <- 0.5 > Q1 <- trmatrix(n, p, r) > coefs <- t(Q1) - diag(n) > wts3 <- solve(rbind(c(rep(1, n)), coefs)[1:n, ], c(1, rep(0, + (n - 1)))) > s3 <- p/r > wts3 <- as.data.frame(wts3) > p <- 0.3 > r <- 0.3 > Q1 <- trmatrix(n, p, r) > coefs <- t(Q1) - diag(n) > wts4 <- solve(rbind(c(rep(1, n)), coefs)[1:n, ], c(1, rep(0, + (n - 1)))) > s4 <- p/r > wts4 <- as.data.frame(wts4) |
> par(mfrow = c(2, 2)) > plot(1:n, wts1[, 1], col = "blue", pch = 19, main = paste("traffic intensity", + s1, " ", "0.6/0.3")) > plot(1:n, wts2[, 1], col = "blue", pch = 19, main = paste("traffic intensity", + s2, " ", "0.3/0.6")) > plot(1:n, wts3[, 1], col = "blue", pch = 19, main = paste("traffic intensity", + s3, " ", "0.5/0.5")) > plot(1:n, wts4[, 1], col = "blue", pch = 19, main = paste("traffic intensity", + s4, " ", "0.3/0.3")) |
if s>1 the chain will explode soon 50 percent of the times