LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
qsys_mg1k_loss.m
1function [lossprob_mg1k,rho]=qsys_mg1k_loss(lambda,svc_density,K)
2% [LOSSPROB,RHO]=QSYS_MG1K_LOSS(LAMBDA,SVC_DENSITY,K)
3%
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
6% Niu-Cooper).
7%
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
16% (aggregated in the last column).
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.
21%
22% TEST:
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)
25%
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.
28
29tmax = 1e4/lambda;
30mu = 1/integral(@(t) t.*svc_density(t),0,tmax);
31a = zeros(1,K-1);
32for j=0:1e3
33 factj = factorial(j);
34 a(1+j)=integral(@(t)exp(-lambda*t).*((lambda*t).^j).*svc_density(t),0,tmax)/factj;
35 if a(1+j)<1e-12
36 break
37 end
38end
39% Embedded chain at service-start epochs, states q=0..K-2 (row/col q+1)
40P = zeros(K-1);
41% row 1 (q=0): idle period after an empty departure epoch
42P(1,1) = a(1+0)+a(1+1);
43for i=1:(K-3)
44 P(1,1+i) = a(1+i+1);
45end
46P(1,K-1) = 1-sum(P(1,1:K-2));
47% row 2 (q=1): q' = number of arrivals during the service (capped)
48if K >= 3
49 for i=0:(K-3)
50 P(2,1+i)=a(1+i);
51 end
52 P(2,K-1)=1-sum(P(2,1:K-2));
53end
54% rows j>=3 (q=j-1): q' = q-1+arrivals (capped)
55for j=3:K-1
56 for i=j-1:(K-2)
57 P(j,i)=a(1+i-j+1);
58 end
59 P(j,K-1)=1-sum(P(j,1:K-2));
60end
61P=dtmc_makestochastic(P);
62sigma = dtmc_solve(P);
63rho = lambda / mu;
64lossprob_mg1k = 1-1/(sigma(1+0)*a(1+0)+rho);
65end
Definition Station.m:245