1function [lossprob_mg1k,rho]=qsys_mg1k_loss(lambda,svc_density,K)
2% [LOSSPROB,RHO]=QSYS_MG1K_LOSS(LAMBDA,SVC_DENSITY,K)
4% Exact M/G/1/K loss probability via
the Markov chain embedded at
5% service-start epochs (transform-free analysis in
the spirit of
8% State: number of customers waiting in
the queue immediately after a
9% service start, q in {0,...,K-2} (capacity K includes
the job in service;
10% just after a departure at most K-1 jobs remain, one of which enters
11% service). With a_j =
P(j Poisson arrivals during a service time):
12% q=0 :
if no arrival occurs during
the service
the system empties and
13%
the next service starts with
the next arrival (q
'=0), so both
14% a_0 and a_1 lead to q'=0 and j>=2 arrivals lead to q
'=j-1;
15% q>=1: q' = q-1+j, with arrivals beyond
the free capacity lost
17% The loss probability follows from
the renewal-reward argument
18% E[cycle] = E[S] + sigma_0*a_0/lambda, lambda_eff = 1/E[cycle],
19% P_loss = 1 - lambda_eff/lambda = 1 - 1/(rho + sigma_0*a_0)
20% where sigma
is the stationary distribution at service-start epochs.
23% mu=3; lambda=2; K=5; [lossprob_mg1k,rho]=qsys_mg1k_loss(lambda,@(t)mu.*exp(-mu.*t),K)
24% (exact M/M/1/5 value: 0.04812030)
26% Reference: Niu, Cooper. Transform-Free Analysis of M/G/1/K and Related
27% Queues. Mathematics of Operations Research 18(2), 1993, 486-510.
30mu = 1/integral(@(t) t.*svc_density(t),0,tmax);
34 a(1+j)=integral(@(t)exp(-lambda*t).*((lambda*t).^j).*svc_density(t),0,tmax)/factj;
39% Embedded chain at service-start epochs, states q=0..K-2 (row/col q+1)
41% row 1 (q=0): idle period after an empty departure epoch
42P(1,1) = a(1+0)+a(1+1);
46P(1,K-1) = 1-sum(
P(1,1:K-2));
47% row 2 (q=1): q
' = number of arrivals during the service (capped)
52 P(2,K-1)=1-sum(P(2,1:K-2));
54% rows j>=3 (q=j-1): q' = q-1+arrivals (capped)
59 P(j,K-1)=1-sum(
P(j,1:K-2));
61P=dtmc_makestochastic(
P);
64lossprob_mg1k = 1-1/(sigma(1+0)*a(1+0)+rho);