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));
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));
171 case {
'adaptive',
'default'}
174 % Sequence of Grundmann-Mueller cubature (CUB) executions
176 % This
is slowish since CUB
is O(N^M) but competitors fails
177 %
'imci' has occasionally large errors in the benchmarks and
178 %
'kt' fails with self-looping customers leading to
179 % degradations see eg in example_mixedModel_4
180 Cmax = M*R*(50)^3; % upper cost budget
181 maxorder = min(ceil((sum(N)-1)/2),16);
184 order = 0; % will be raised as far as possible
185 while order < maxorder
186 nextCost = R * nchoosek(M + 2*(order+1), M-1); % cost of order+1
187 if totCost + nextCost <= Cmax
189 totCost = totCost + nextCost;
195 [~,lG] = pfqn_cub(L,N,sum(Z,1),order,GlobalConstants.FineTol);
198 [~,lG] = pfqn_le(L,N,sum(Z,1));
201 elseif sum(Z(:))==0 % single queue, no delay
204 else % repairman model
206 % gleint is a better method but there are JAR loading issues
207 % at times upon loading the txt files
208 %[~,lG] = pfqn_mmint2_gausslegendre(L,N,sum(Z,1));
210 [lG] = pfqn_comomrm(L,N,Z,1,options.tol);
213 [~,lG] = pfqn_le(L,N,sum(Z,1));
219 [~,lG] = pfqn_mmsample2(L,N,sum(Z,1),options.samples);
222 [~,lG] = pfqn_mci(L,N,sum(Z,1),options.samples,'imci
');
225 [~,lG] = pfqn_ls(L,N,sum(Z,1),options.samples);
228 case {'mmint2
','gleint
'}
231 line_warning(mfilename,sprintf('The %s method requires a model with a delay and a single queueing station.
',options.method));
236 [~,lG] = pfqn_mmint2_gausslegendre(L,N,sum(Z,1));
237 case {'cub
','gm
'} % Grundmann-Mueller cubatures
238 order = ceil((sum(N)-1)/2); % exact
239 [~,lG] = pfqn_cub(L,N,sum(Z,1),order,GlobalConstants.FineTol);
241 [~,lG] = pfqn_kt(L,N,sum(Z,1));
243 [~,lG] = pfqn_le(L,N,sum(Z,1));
245 [~,lG] = pfqn_ls(L,N,sum(Z,1),options.samples);
247 [~,lG] = pfqn_mci(L,N,sum(Z,1),options.samples,options.method);
249 [~,~,~,~,lG] = pfqn_mva(L,N,sum(Z,1));
251 % line_warning(mfilename,'mom supported only in SolverJMT (method ).
');
253 if M>=R || sum(N)>10 || sum(Z(:))>0
254 [~,lG] = pfqn_ca(L,N,sum(Z,1));
257 [~,lG] = pfqn_recal(L,N,sum(Z,1));% implemented with Z=0
258 method = 'exact/recal
';
263 % comom has a bug in computing X, sometimes the
267 line_warning(mfilename,'comom supported only for M=1 queue. Use SolverJMT instead (method jmva.comom).
');
271 else % use double precision script for M=1
272 [lG] = pfqn_comomrm(L,N,Z,1,options.tol);
275 getReport(ME,'basic
')
276 % java exception, probably singular linear system
278 %line_warning(mfilename,'Numerical problems.
');
283 [~,lG] = pfqn_ca(L,N,sum(Z,1));
287 [~,lG] = pfqn_panacea(L,N,sum(Z,1));
290 line_warning(mfilename,'Model
is not in normal usage, panacea cannot continue.\n
');
296 [~,lG] = pfqn_propfair(L,N,sum(Z,1));
300 line_warning(mfilename,'RECAL
is currently available only for models with non-zero think times.\n
');
305 [~,lG] = pfqn_recal(L,N,sum(Z,1));
309 % line_warning(mfilename,'RGF
is defined only for models with non-zero think times.\n
');
314 % [~,lG] = pfqn_rgf(L,N);
320 line_warning(mfilename,sprintf('Unrecognized method: %s
',options.method));