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
34 Ut(i) = (1-lambda*L(i,:)');
38 L(i,:) = L(i,:)/Ut(i);
39 Qopen(i,:) = lambda.*L(i,:)/Ut(i);
40 %lGopen = lGopen + log(Ut(i));
49lambda = lambda(:,nnzClasses);
54% then scale demands in [0,1], importat that stays before the other
55% simplications in case both D and Z are all very small or very large in a
56% given class, in which case the may look to filter but not if all of them
57% are at the same scale
61% case {
'adaptive',
'comom',
'default'}
66 scalevec(r) = max([L(:,r);Z(:,r)]);
69L = L ./ repmat(scalevec,size(L,1),1);
72% remove stations with no demand
75demStations = find((Lmax./Lsum)>GlobalConstants.FineTol);
76noDemStations = setdiff(1:size(L,1), demStations);
78if any(N((sum(L,1) + sum(Z,1)) == 0)>0) %
if there
is a
class with jobs but L and Z all zero
80 line_warning(mfilename,'The model has no positive demands in any class.\n');
82 if isempty(Z) || sum(Z(:))<options.tol
85 lG = - sum(factln(N)) + sum(N.*log(sum(Z,1))) + N*log(scalevec)
';
93% return immediately if degenerate case
94if isempty(L) || sum(L(:))<options.tol % all demands are zero
95 if isempty(Z) || sum(Z(:))<options.tol
98 lG = lGopen - sum(factln(N)) + sum(N.*log(sum(Z,1))) + N*log(scalevec)';
101elseif M==1 && (isempty(Z) || sum(Z(:))<options.tol) % single node and no think time
102 lG = factln(sum(N)) - sum(factln(N)) + sum(N.*log(L(1,:))) + N*log(scalevec)
';
104elseif size(unique(L,'rows
'),1)==1 && (isempty(Z) || sum(Z(:))<options.tol) % M identical replicas
105 lG = factln(sum(N)+M-1) - sum(factln(N)) + sum(N.*log(L(1,:))) + N*log(scalevec)' - factln(M-1);
109% determine contribution from jobs that permanently loop at delay
110zeroDemandClasses = find(sum(L,1)<options.tol); % all jobs in delay
111nonzeroDemandClasses = setdiff(1:R, zeroDemandClasses);
113if isempty(sum(Z,1)) || all(sum(Z(:,zeroDemandClasses),1)<options.tol)
117 if isempty(zeroDemandClasses) %
for old MATLAB release compatibility
121 Nz = N(zeroDemandClasses);
122 lGzdem = - sum(factln(Nz)) + sum(Nz.*log(sum(Z(:,zeroDemandClasses),1))) + Nz*log(scalevec(zeroDemandClasses))
';
125L = L(:,nonzeroDemandClasses);
126N = N(nonzeroDemandClasses);
127Zz = Z(:,zeroDemandClasses);
128Z = Z(:,nonzeroDemandClasses);
129scalevecz = scalevec(nonzeroDemandClasses);
130% compute G for classes No with non-zero demand
131[lGnzdem,Xnnzdem,Qnnzdem,method] = compute_norm_const(L, N, Z, options);
133if isempty(Xnnzdem) % in this case the NC method does not return metrics as a by-product
137 zClasses = setdiff(1:Rin, nnzClasses);
138 Xz = zeros(1,length(zClasses));
139 Xnnz = zeros(1,length(nnzClasses));
140 Xnnz(zeroDemandClasses) = Nz./ sum(Zz,1)./ scalevec(zeroDemandClasses);
141 Xnnz(nonzeroDemandClasses) = Xnnzdem./ scalevec(nonzeroDemandClasses);
142 X(1,[zClasses, nnzClasses]) = [Xz, Xnnz];
143 X(ocl) = lambda(ocl);
144 Qz = zeros(size(Qnnzdem,1),length(zClasses));
145 Qnnz = zeros(size(Qnnzdem,1),length(nnzClasses));
146 Qnnz(:,zeroDemandClasses) = 0; % they are all in the delay
147 Qnnz(:,nonzeroDemandClasses) = Qnnzdem; % Q does not require scaling
148 Q(noDemStations,:) = 0;
149 Q(demStations,[zClasses, nnzClasses]) = [Qz, Qnnz];
150 Q(:,ocl) = Qopen(:,ocl);
152% scale back to original demands
153lG = lGopen + lGnzdem + lGzdem + N*log(scalevecz)';
156function [lG,X,Q,method] = compute_norm_const(L,N,Z,options)
157% LG = COMPUTE_NORM_CONST(L,N,Z,OPTIONS)
158% Auxiliary script that computes LG after the initial filtering of L,N,Z
160% Note: methods that can handle more efficiently replicas need to
do so
161% within the method function
166method = options.method;
169 [~,lG] = pfqn_ca(L,N,sum(Z,1));
170 case {
'adaptive',
'default'}
173 % Sequence of Grundmann-Mueller cubature (CUB) executions
175 % This
is slowish since CUB
is O(N^M) but competitors fails
176 %
'imci' has occasionally large errors in the benchmarks and
177 %
'kt' fails with self-looping customers leading to
178 % degradations see eg in example_mixedModel_4
179 Cmax = M*R*(50)^3; % upper cost budget
180 maxorder = min(ceil((sum(N)-1)/2),16);
183 order = 0; % will be raised as far as possible
184 while order < maxorder
185 nextCost = R * nchoosek(M + 2*(order+1), M-1); % cost of order+1
186 if totCost + nextCost <= Cmax
188 totCost = totCost + nextCost;
194 [~,lG] = pfqn_cub(L,N,sum(Z,1),order,GlobalConstants.FineTol);
197 [~,lG] = pfqn_le(L,N,sum(Z,1));
200 elseif sum(Z(:))==0 % single queue, no delay
203 else % repairman model
205 % gleint is a better method but there are JAR loading issues
206 % at times upon loading the txt files
207 %[~,lG] = pfqn_mmint2_gausslegendre(L,N,sum(Z,1));
209 [lG] = pfqn_comomrm(L,N,Z,1,options.tol);
212 [~,lG] = pfqn_le(L,N,sum(Z,1));
218 [~,lG] = pfqn_mmsample2(L,N,sum(Z,1),options.samples);
221 [~,lG] = pfqn_mci(L,N,sum(Z,1),options.samples,'imci
');
224 [~,lG] = pfqn_ls(L,N,sum(Z,1),options.samples);
227 case {'mmint2
','gleint
'}
230 line_warning(mfilename,sprintf('The %s method requires a model with a delay and a single queueing station.
',options.method));
235 [~,lG] = pfqn_mmint2_gausslegendre(L,N,sum(Z,1));
236 case {'cub
','gm
'} % Grundmann-Mueller cubatures
237 order = ceil((sum(N)-1)/2); % exact
238 [~,lG] = pfqn_cub(L,N,sum(Z,1),order,GlobalConstants.FineTol);
240 [~,lG] = pfqn_kt(L,N,sum(Z,1));
242 [~,lG] = pfqn_le(L,N,sum(Z,1));
244 [~,lG] = pfqn_ls(L,N,sum(Z,1),options.samples);
246 [~,lG] = pfqn_mci(L,N,sum(Z,1),options.samples,options.method);
248 [~,~,~,~,lG] = pfqn_mva(L,N,sum(Z,1));
250 % line_warning(mfilename,'mom supported only in SolverJMT (method ).
');
252 if M>=R || sum(N)>10 || sum(Z(:))>0
253 [~,lG] = pfqn_ca(L,N,sum(Z,1));
256 [~,lG] = pfqn_recal(L,N,sum(Z,1));% implemented with Z=0
257 method = 'exact/recal
';
262 % comom has a bug in computing X, sometimes the
266 line_warning(mfilename,'comom supported only for M=1 queue. Use SolverJMT instead (method jmva.comom).
');
270 else % use double precision script for M=1
271 [lG] = pfqn_comomrm(L,N,Z,1,options.tol);
274 getReport(ME,'basic
')
275 % java exception, probably singular linear system
277 %line_warning(mfilename,'Numerical problems.
');
282 [~,lG] = pfqn_ca(L,N,sum(Z,1));
286 [~,lG] = pfqn_panacea(L,N,sum(Z,1));
289 line_warning(mfilename,'Model
is not in normal usage, panacea cannot continue.\n
');
295 [~,lG] = pfqn_propfair(L,N,sum(Z,1));
299 line_warning(mfilename,'RECAL
is currently available only for models with non-zero think times.\n
');
304 [~,lG] = pfqn_recal(L,N,sum(Z,1));
308 % line_warning(mfilename,'RGF
is defined only for models with non-zero think times.\n
');
313 % [~,lG] = pfqn_rgf(L,N);
319 line_warning(mfilename,sprintf('Unrecognized method: %s
',options.method));