LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sum_closed.m
1function [XN,QN,UN,RN,it] = sum_closed(L,N,Z,mi,scv,tol,maxiter)
2% [XN,QN,UN,RN,IT] = SUM_CLOSED(L,N,Z,MI,SCV,TOL,MAXITER)
3%
4% Summation method (SUM) for closed queueing networks, including the
5% extended SUM (ESUM) node functions for non-product-form networks with
6% generally distributed service times.
7%
8% The method expresses the mean queue length of each station as a function
9% of its throughput, Ki = fi(lambdai), and solves the population constraint
10% sum_i Ki = K. Single-class models are solved by bisection on the system
11% throughput (Bolch et al., Sec. 9.2.1); multiclass models by fixed-point
12% iteration on the class throughputs (Sec. 9.2.2, Eqs. 9.24-9.26).
13%
14% Node functions:
15% - Product-form stations (scv=1, or insensitive disciplines PS/LCFS-PR,
16% for which the caller must pass scv=1): Eq. (9.15)/(9.19).
17% - FCFS stations with general service (scv~=1): ESUM corrections,
18% Eq. (10.88) for -/G/1 and Eq. (10.89) for -/G/m, with
19% ai=(1+scv_i)/2 and Erlang-C waiting probability P_mi.
20% - Infinite-server stations (mi=Inf) and think times Z: Ki = lambdai*Li.
21%
22% Input:
23% L - MxR service demand matrix, L(i,r) = e(i,r)/mu(i,r)
24% N - 1xR population vector
25% Z - 1xR think times (aggregated as a delay term)
26% mi - Mx1 number of servers (Inf for infinite-server stations)
27% scv - MxR squared coefficient of variation of service times
28% tol - convergence tolerance (default: 1e-6)
29% maxiter - maximum number of iterations (default: 10000)
30%
31% Output:
32% XN - 1xR class throughputs
33% QN - MxR mean queue lengths
34% UN - MxR utilizations (per-server for queueing stations, X.*L for IS)
35% RN - MxR residence times, RN=QN./XN
36% it - number of iterations
37%
38% Reference: G. Bolch, S. Greiner, H. de Meer, K.S. Trivedi, Queueing
39% Networks and Markov Chains, 2nd ed., Wiley, 2006, Secs. 9.2 and 10.1.4.4.
40
41% Copyright (c) 2012-2026, Imperial College London
42% All rights reserved.
43
44[M,R] = size(L);
45if nargin<3 || isempty(Z), Z = zeros(1,R); end
46if nargin<4 || isempty(mi), mi = ones(M,1); end
47if nargin<5 || isempty(scv), scv = ones(M,R); end
48if nargin<6 || isempty(tol), tol = 1e-6; end
49if nargin<7 || isempty(maxiter), maxiter = 10000; end
50mi = mi(:);
51Z = Z(:)';
52N = N(:)';
53K = sum(N(isfinite(N)));
54
55XN = zeros(1,R);
56QN = zeros(M,R);
57UN = zeros(M,R);
58RN = zeros(M,R);
59it = 0;
60
61if K==0
62 return
63end
64
65if R==1
66 % single class: bisection on the throughput (Sec. 9.2.1)
67 lambda_l = 0;
68 lambda_u = Inf;
69 for i=1:M
70 if L(i)>0
71 if isinf(mi(i))
72 lambda_u = min(lambda_u, K/L(i));
73 else
74 lambda_u = min(lambda_u, mi(i)/L(i));
75 end
76 end
77 end
78 if Z>0
79 lambda_u = min(lambda_u, K/Z);
80 end
81 if isinf(lambda_u)
82 line_error(mfilename,'All service demands are zero.');
83 end
84 lambda = lambda_u;
85 for it=1:maxiter
86 lambda = (lambda_l+lambda_u)/2;
87 g = lambda*Z + sum(sum_node_qlen(L,lambda,mi,scv,K));
88 if abs(g-K)<=tol || (lambda_u-lambda_l)<=tol*lambda_u
89 break
90 end
91 if g>K
92 lambda_u = lambda;
93 else
94 lambda_l = lambda;
95 end
96 end
97 XN = lambda;
98else
99 % multiclass: Gauss-Seidel sweeps of per-class bisections on the
100 % population constraints sum_i fir(lambda_r)+lambda_r*Zr = Nr. This is
101 % a robust alternative to the successive substitution of Sec. 9.2.2,
102 % which can overshoot the saturation polytope for large populations.
103 XN = zeros(1,R);
104 for it=1:maxiter
105 delta = 0;
106 for r=1:R
107 if N(r)==0
108 continue
109 end
110 % upper bound for lambda_r given the other class throughputs
111 ub = Inf;
112 for i=1:M
113 if L(i,r)>0
114 if isinf(mi(i))
115 ub = min(ub, K/L(i,r));
116 else
117 rem = mi(i) - (XN*L(i,:)' - XN(r)*L(i,r));
118 ub = min(ub, max(rem,0)/L(i,r));
119 end
120 end
121 end
122 if Z(r)>0
123 ub = min(ub, N(r)/Z(r));
124 end
125 if isinf(ub)
126 line_error(mfilename,'All service demands are zero.');
127 end
128 lambda_old = XN(r);
129 lambda_l = 0;
130 lambda_u = ub;
131 while (lambda_u-lambda_l) > tol*max(ub,1)/1e3
132 lambda = (lambda_l+lambda_u)/2;
133 XN(r) = lambda;
134 Qir = sum_node_qlen(L,XN,mi,scv,K);
135 g = lambda*Z(r) + sum(Qir(:,r));
136 if g>N(r)
137 lambda_u = lambda;
138 else
139 lambda_l = lambda;
140 end
141 end
142 XN(r) = (lambda_l+lambda_u)/2;
143 delta = max(delta, abs(XN(r)-lambda_old));
144 end
145 if delta<=tol
146 break
147 end
148 end
149end
150
151QN = sum_node_qlen(L,XN,mi,scv,K);
152for i=1:M
153 for r=1:R
154 if isinf(mi(i))
155 UN(i,r) = XN(r)*L(i,r);
156 else
157 UN(i,r) = XN(r)*L(i,r)/mi(i);
158 end
159 if XN(r)>0
160 RN(i,r) = QN(i,r)/XN(r);
161 end
162 end
163end
164end
165
166function Qir = sum_node_qlen(L,XN,mi,scv,K)
167% per-station per-class mean queue lengths Ki_r = fir(lambda_r)
168[M,R] = size(L);
169Qir = zeros(M,R);
170for i=1:M
171 if isinf(mi(i))
172 Qir(i,:) = XN.*L(i,:); % Type 3, Eq. (9.15)
173 continue
174 end
175 m = mi(i);
176 Uir = XN.*L(i,:); % class offered loads lambda_r*e_ir/mu_ir
177 rho = min(sum(Uir)/m, 1); % per-server utilization; the correction
178 % factors keep the node functions finite at rho=1 (Ki(1)<=K)
179 if sum(Uir)==0
180 continue
181 end
182 % demand-weighted node service SCV
183 ci2 = sum(Uir.*scv(i,:))/sum(Uir);
184 ai = (1+ci2)/2;
185 if K<=m
186 % never more than m jobs at a m-server node: no queueing
187 Qir(i,:) = Uir;
188 continue
189 end
190 if m==1
191 if ci2==1 || K<=1
192 % Type 1,2,4 with mi=1, Eq. (9.15)/(9.19)
193 Qir(i,:) = Uir/(1-(K-1)/K*rho);
194 else
195 % -/G/1 FCFS, Eq. (10.88)
196 den = 1-(K-1-ai)/(K-1)*rho;
197 Qir(i,:) = Uir.*(1+rho*ai/den);
198 end
199 else
200 Pm = sum_erlangc(m,rho);
201 if ci2==1
202 % Type 1 with mi>1, Eq. (9.15)/(9.19)
203 den = 1-(K-m-1)/(K-m)*rho;
204 Qir(i,:) = Uir + (Uir/m)*Pm/den;
205 else
206 % -/G/m FCFS, Eq. (10.89)
207 den = 1-(K-m-ai)/(K-m)*rho;
208 Qir(i,:) = Uir + (Uir/m)*ai*Pm/den;
209 end
210 end
211end
212end
213
214function Pm = sum_erlangc(m,rho)
215% Erlang-C probability of waiting for an M/M/m queue (Eq. 6.28)
216if rho>=1
217 Pm = 1;
218 return
219end
220a = m*rho;
221s = 0;
222for k=0:(m-1)
223 s = s + a^k/factorial(k);
224end
225last = a^m/(factorial(m)*(1-rho));
226Pm = last/(s+last);
227end
Definition Station.m:245