Created
October 10, 2018 09:51
-
-
Save EvanMu96/3e0875ada32e2f74aa408e5cef7434fe to your computer and use it in GitHub Desktop.
Markov Chain Simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Compat, Random, Distributions | |
# to set a markov chain, use a dictionary data structure like this. | |
example_set = Dict("lambda"=>19.5, "mu"=>1, "k"=>10, "max_na"=>500000) | |
# Uniform distribution | |
uniform_d = Uniform() | |
function Markov_Chain(paratmers) | |
global uniform_d | |
# initialize paratmers | |
# queue size | |
Q_size = 0 | |
# N_a is number of customer arrivals counted so far | |
# N_b is number of blocked customers counted so far | |
N_a, N_b = 0, 0 | |
lambda = paratmers["lambda"] | |
mu = paratmers["mu"] | |
k = paratmers["k"] | |
max_na = paratmers["max_na"] | |
rand_X = rand(uniform_d, max_na) | |
for x in rand_X | |
if x < lambda/(lambda+Q_size*mu) | |
N_a = N_a + 1 | |
if Q_size == k | |
N_b = N_b + 1 | |
#println("Blocking happens") | |
else | |
Q_size = Q_size + 1 | |
end | |
else | |
Q_size = Q_size - 1 | |
end | |
end | |
return N_b/N_a | |
end | |
test_case = Dict("lambda"=>19.5, "mu"=>1, "k"=>10, "max_na"=>100000000) | |
result_set = [] | |
for i=1:10 | |
x = Markov_Chain(test_case) | |
push!(result_set, x) | |
end | |
E_x = mean(result_set) | |
Var_x = var(result_set) | |
sigma = sqrt(Var_x) | |
Ur = 2.23*(sigma/sqrt(11)) | |
lower_bound = E_x-Ur | |
upper_bound = E_x+Ur | |
println("Mean blocking probability:$(E_x)") | |
println("Confidence Interval 95%:($(lower_bound), $(upper_bound))\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment