1% Computes
the normalizing constant of a product-form queueing network.
2% [LG,X,Q,METHOD] = PFQN_NC(LAMBDA,L,N,Z,VARARGIN)
3function [lG,X,Q,method] = pfqn_nc(lambda,L,N,Z,varargin)
5options = Solver.parseOptions(varargin, SolverNC.defaultOptions);
6method =
'exact'; %
if early
return is triggered
7% backup initial parameters
10if any(N<0) || isempty(N)
30% compute open
class contributions
33Ut = zeros(1, size(L,1));
35 Ut(i) = (1-lambda*L(i,:)');
39 L(i,:) = L(i,:)/Ut(i);
40 Qopen(i,:) = lambda.*L(i,:)/Ut(i);
41 %lGopen = lGopen + log(Ut(i));
45% then erase open classes
48% first remove empty classes
50lambda = lambda(:,nnzClasses);
55% then scale demands in [0,1], importat that stays before
the other
56% simplications in case both D and Z are all very small or very large in a
57% given class, in which case
the may look to filter but not if all of them
58% are at
the same scale
62% case {
'adaptive',
'comom',
'default'}
67 scalevec(r) = max([L(:,r);Z(:,r)]);
70L = L ./ repmat(scalevec,size(L,1),1);
73% remove stations with no demand
76demStations = find((Lmax./Lsum)>GlobalConstants.FineTol);
77noDemStations = setdiff(1:size(L,1), demStations);
79if any(N((sum(L,1) + sum(Z,1)) == 0)>0) %
if there
is a
class with jobs but L and Z all zero
81 line_warning(mfilename,'The model has no positive demands in any class.\n');
83 if isempty(Z) || sum(Z(:))<options.tol
86 lG = - sum(factln(N)) + sum(N.*log(sum(Z,1))) + N*log(scalevec)
';
94% return immediately if degenerate case
95if isempty(L) || sum(L(:))<options.tol % all demands are zero
96 if isempty(Z) || sum(Z(:))<options.tol
99 lG = lGopen - sum(factln(N)) + sum(N.*log(sum(Z,1))) + N*log(scalevec)';
102elseif M==1 && (isempty(Z) || sum(Z(:))<options.tol) % single node and no think time
103 lG = factln(sum(N)) - sum(factln(N)) + sum(N.*log(L(1,:))) + N*log(scalevec)
';
105elseif size(unique(L,'rows
'),1)==1 && (isempty(Z) || sum(Z(:))<options.tol) % M identical replicas
106 lG = factln(sum(N)+M-1) - sum(factln(N)) + sum(N.*log(L(1,:))) + N*log(scalevec)' - factln(M-1);
110% determine contribution from jobs that permanently loop at delay
111zeroDemandClasses = find(sum(L,1)<options.tol); % all jobs in delay
112nonzeroDemandClasses = setdiff(1:R, zeroDemandClasses);
114if isempty(sum(Z,1)) || all(sum(Z(:,zeroDemandClasses),1)<options.tol)
118 if isempty(zeroDemandClasses) %
for old MATLAB release compatibility
122 Nz = N(zeroDemandClasses);
123 lGzdem = - sum(factln(Nz)) + sum(Nz.*log(sum(Z(:,zeroDemandClasses),1))) + Nz*log(scalevec(zeroDemandClasses))
';
126L = L(:,nonzeroDemandClasses);
127N = N(nonzeroDemandClasses);
128Zz = Z(:,zeroDemandClasses);
129Z = Z(:,nonzeroDemandClasses);
130scalevecz = scalevec(nonzeroDemandClasses);
131% compute G for classes No with non-zero demand
132[lGnzdem,Xnnzdem,Qnnzdem,method] = compute_norm_const(L, N, Z, options);
134if isempty(Xnnzdem) % in this case the NC method does not return metrics as a by-product
138 zClasses = setdiff(1:Rin, nnzClasses);
139 Xz = zeros(1,length(zClasses));
140 Xnnz = zeros(1,length(nnzClasses));
141 Xnnz(zeroDemandClasses) = Nz./ sum(Zz,1)./ scalevec(zeroDemandClasses);
142 Xnnz(nonzeroDemandClasses) = Xnnzdem./ scalevec(nonzeroDemandClasses);
143 X(1,[zClasses, nnzClasses]) = [Xz, Xnnz];
144 X(ocl) = lambda(ocl);
145 Qz = zeros(size(Qnnzdem,1),length(zClasses));
146 Qnnz = zeros(size(Qnnzdem,1),length(nnzClasses));
147 Qnnz(:,zeroDemandClasses) = 0; % they are all in the delay
148 Qnnz(:,nonzeroDemandClasses) = Qnnzdem; % Q does not require scaling
149 Q(noDemStations,:) = 0;
150 Q(demStations,[zClasses, nnzClasses]) = [Qz, Qnnz];
151 Q(:,ocl) = Qopen(:,ocl);
153% scale back to original demands
154lG = lGopen + lGnzdem + lGzdem + N*log(scalevecz)';
157function [lG,X,Q,method] = compute_norm_const(L,N,Z,options)
158% LG = COMPUTE_NORM_CONST(L,N,Z,OPTIONS)
159% Auxiliary script that computes LG after
the initial filtering of L,N,Z
161% Note: methods that can handle more efficiently replicas need to
do so
162% within
the method function
167method = options.method;
170 [~,lG] = pfqn_ca(L,N,sum(Z,1));
172 % Choudhury-Leung-Whitt generating function inversion: each
173 % single-server station
is a multiplicity-1 queue, delay
is the IS term
174 [~,lG] = pfqn_clw(L,N,sum(Z,1));
175 case {
'adaptive',
'default'}
178 % Sequence of Grundmann-Mueller cubature (CUB) executions
180 % This
is slowish since CUB
is O(N^M) but competitors fails
181 %
'imci' has occasionally large errors in
the benchmarks and
182 %
'kt' fails with self-looping customers leading to
183 % degradations see eg in example_mixedModel_4
184 Cmax = M*R*(50)^3; % upper cost budget
185 maxorder = min(ceil((sum(N)-1)/2),16);
188 order = 0; % will be raised as far as possible
189 while order < maxorder
190 nextCost = R * nchoosek(M + 2*(order+1), M-1); % cost of order+1
191 if totCost + nextCost <= Cmax
193 totCost = totCost + nextCost;
199 [~,lG] = pfqn_cub(L,N,sum(Z,1),order,GlobalConstants.FineTol);
202 [~,lG] = pfqn_le(L,N,sum(Z,1));
205 elseif sum(Z(:))==0 % single queue, no delay
208 else % repairman model
210 % gleint is a better method but there are JAR loading issues
211 % at times upon loading the txt files
212 %[~,lG] = pfqn_mmint2_gausslegendre(L,N,sum(Z,1));
214 [lG] = pfqn_comomrm(L,N,Z,1,options.tol);
217 [~,lG] = pfqn_le(L,N,sum(Z,1));
223 [~,lG] = pfqn_mmsample2(L,N,sum(Z,1),options.samples);
226 [~,lG] = pfqn_mci(L,N,sum(Z,1),options.samples,'imci
');
229 [~,lG] = pfqn_ls(L,N,sum(Z,1),options.samples);
232 case {'mmint2
','gleint
'}
235 line_warning(mfilename,sprintf('The %s method requires a model with a delay and a single queueing station.
',options.method));
240 [~,lG] = pfqn_mmint2_gausslegendre(L,N,sum(Z,1));
241 case {'cub
','gm
'} % Grundmann-Mueller cubatures
242 order = ceil((sum(N)-1)/2); % exact
243 [~,lG] = pfqn_cub(L,N,sum(Z,1),order,GlobalConstants.FineTol);
245 [~,lG] = pfqn_kt(L,N,sum(Z,1));
247 [~,lG] = pfqn_le(L,N,sum(Z,1));
249 [~,lG] = pfqn_ls(L,N,sum(Z,1),options.samples);
251 % Importance sampling for a load-independent closed network: the
252 % sample-an-ordering estimator of pfqn_is. The order-independent and
253 % pass-and-swap cases are intercepted upstream by solver_nc_analyzer,
254 % which routes to pfqn_pas_is / pfqn_oi_is instead.
255 [~,lG] = pfqn_is(L,N,sum(Z,1),options);
258 [~,lG] = pfqn_mci(L,N,sum(Z,1),options.samples,options.method);
260 [~,~,~,~,lG] = pfqn_mva(L,N,sum(Z,1));
262 % line_warning(mfilename,'mom supported only in SolverJMT (method ).
');
264 if M>=R || sum(N)>10 || sum(Z(:))>0
265 [~,lG] = pfqn_ca(L,N,sum(Z,1));
268 [~,lG] = pfqn_recal(L,N,sum(Z,1));% implemented with Z=0
269 method = 'exact/recal
';
273 % comom evaluates the normalizing constant of the repairman model,
274 % so it needs a single queueing station. This is checked BEFORE the
275 % try below on purpose: line_error must not be swallowed by that
276 % catch and turned back into an empty lG.
278 % This used to emit a warning gated on options.verbose and then
279 % return lG = [], which the caller turned into all-zero queue
280 % lengths while still reporting a completed analysis. A silently
281 % zeroed result is worse than no result: refuse instead.
283 line_error(mfilename,'The
''comom
'' method supports a single queueing station, but this model has %d. Use
''default
'' or
''ca
'' for an exact normalizing constant, or SolverJMT with method
''jmva.comom
''.
', M);
286 % comom has a bug in computing X, sometimes the
288 [lG] = pfqn_comomrm(L,N,Z,1,options.tol);
290 getReport(ME,'basic
')
291 % java exception, probably singular linear system
293 %line_warning(mfilename,'Numerical problems.
');
298 [~,lG] = pfqn_ca(L,N,sum(Z,1));
302 [~,lG] = pfqn_panacea(L,N,sum(Z,1));
305 line_warning(mfilename,'Model
is not in normal usage, panacea cannot continue.\n
');
311 [~,lG] = pfqn_propfair(L,N,sum(Z,1));
315 line_warning(mfilename,'RECAL
is currently available only for models with non-zero think times.\n
');
320 [~,lG] = pfqn_recal(L,N,sum(Z,1));
324 % line_warning(mfilename,'RGF
is defined only for models with non-zero think times.\n
');
329 % [~,lG] = pfqn_rgf(L,N);
335 line_warning(mfilename,sprintf('Unrecognized method: %s
',options.method));