LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
qsys_gg1.m
1function [W,rhohat]=qsys_gg1(lambda,mu,ca2,cs2)
2% [W,RHOHAT]=QSYS_GG1(LAMBDA,MU,CA2,CS2) analyzes a G/G/1 queue.
3%
4% Uses exact methods for special cases (M/M/1, M/G/1, G/M/1) and
5% Allen-Cunneen approximation for the general case. In the G/M/1 case,
6% the interarrival-time distribution is fitted from (LAMBDA,CA2) by a
7% two-moment renewal process (H2 with balanced means for CA2>1, mixed
8% Erlang for CA2<1) and sigma is the root of sigma = A*(mu*(1-sigma)),
9% with A* the interarrival-time LST.
10%
11% Inputs:
12% LAMBDA - Arrival rate
13% MU - Service rate
14% CA2 - Squared coefficient of variation of inter-arrival time
15% CS2 - Squared coefficient of variation of service time
16%
17% Returns:
18% W - Average time in system (response time)
19% RHOHAT - Modified utilization (so that M/M/1 formulas still hold)
20
21% Copyright (c) 2012-2026, Imperial College London
22% All rights reserved.
23
24tol = 1e-8;
25
26if abs(ca2 - 1) < tol && abs(cs2 - 1) < tol
27 % M/M/1 case
28 [W,rhohat] = qsys_mm1(lambda, mu);
29elseif abs(ca2 - 1) < tol
30 % M/G/1 case (ca2 = 1)
31 [W,rhohat] = qsys_mg1(lambda, mu, sqrt(cs2));
32elseif abs(cs2 - 1) < tol
33 % G/M/1 case (cs2 = 1)
34 sigma = qsys_gm1_sigma(lambda, mu, ca2);
35 W = qsys_gm1(sigma, mu);
36 rhohat = W * lambda / (1 + W * lambda);
37else
38 % General G/G/1 case - use Allen-Cunneen approximation
39 [W,rhohat] = qsys_gig1_approx_allencunneen(lambda, mu, sqrt(ca2), sqrt(cs2));
40end
41
42end
43
44function sigma = qsys_gm1_sigma(lambda, mu, ca2)
45% Root in (0,1) of sigma = A*(mu*(1-sigma)) for a two-moment fit of the
46% interarrival-time LST A*. (Handle-free so that MATLAB Coder can mexify.)
47jj = 0; p = 0; nu = 0; p1 = 0; l1 = 0; l2 = 0;
48if ca2 >= 1
49 % hyperexponential H2 with balanced means
50 p1 = (1 + sqrt((ca2-1)/(ca2+1)))/2;
51 l1 = 2*p1*lambda;
52 l2 = 2*(1-p1)*lambda;
53elseif ca2 >= 1e-6
54 % mixed Erlang(j-1,j) with common rate (Tijms, 1994)
55 jj = ceil(1/ca2);
56 p = (jj*ca2 - sqrt(jj*(1+ca2) - jj^2*ca2))/(1+ca2);
57 nu = (jj - p)*lambda;
58end
59% fixed-point iteration; T(x)=A*(mu*(1-x)) is increasing with the queue
60% root as its smallest fixed point, so iterates converge monotonically
61sigma = lambda/mu;
62for it=1:100000
63 s = mu*(1-sigma);
64 if ca2 < 1e-6
65 % deterministic interarrival times
66 signew = exp(-s/lambda);
67 elseif ca2 < 1
68 signew = p*(nu/(s+nu))^(jj-1) + (1-p)*(nu/(s+nu))^jj;
69 else
70 signew = p1*l1/(s+l1) + (1-p1)*l2/(s+l2);
71 end
72 if abs(signew-sigma) < 1e-13
73 sigma = signew;
74 return
75 end
76 sigma = signew;
77end
78end
Definition Station.m:245