3 % @file pfqn_nc_sanitize.m
4 % @brief Sanitize and preprocess network parameters
for NC solvers.
10 % @brief Sanitize and preprocess network parameters
for NC solvers.
11 % @fn pfqn_nc_sanitize(lambda, L, N, Z, atol)
12 % @param lambda Arrival rate vector.
13 % @param L Service demand matrix.
14 % @param N Population vector.
15 % @param Z Think time vector.
16 % @param atol Absolute tolerance.
17 % @
return lambda Sanitized arrival rates.
18 % @
return L Sanitized service demands (rescaled).
19 % @
return N Sanitized populations.
20 % @
return Z Sanitized think times (rescaled).
21 % @
return lGremaind Log normalization
factor from removed classes.
24function [lambda,L,N,Z,lGremaind] = pfqn_nc_sanitize(lambda,L,N,Z,atol)
32lambda=lambda(:,nnzclasses);
33% erase ill-defined classes
34zeroclasses=find((sum(L,1)+sum(Z,1))<atol);
38lambda(:,zeroclasses)=[];
41% find zero demand classes
42% see _kb/03-api-layer.md (pfqn/ family: scaling, log-domain switches, dispatch gates)
43zerodemands=find(sum(L,1)<atol);
44if ~isempty(zerodemands)
45 lGremaind = lGremaind + N(zerodemands) * log(sum(Z(:,zerodemands),1))
' - sum(factln(N(zerodemands)));
49 lambda(:,zerodemands)=[];
52Lmax = max(L,[],1); % use L, which has been santized to always be ~=0
54 Lmax = ones(1,size(Z,2));
56L = L./repmat(Lmax,size(L,1),1);
57Z = Z./repmat(Lmax,size(Z,1),1);
58lGremaind = lGremaind + N*log(Lmax)';
59% sort from smallest to largest think time
60% see _kb/03-api-layer.md (pfqn/ family: scaling, log-domain switches, dispatch gates)
62 [~,rsort] = sort(sum(Z,1),
'ascend');
69 lambda=lambda(:,rsort);
72% ensure zero think time classes are anyway first. The test
is on the COLUMN
73% SUM: find() on the (K x R) matrix Z returns
column-major LINEAR indices, and
74% using them as
column indices
is only correct when Z has a single row.
75zerothinktimes=find(sum(Z,1)<atol);
76nonzerothinktimes = setdiff(1:size(L,2),zerothinktimes);
77L=L(:,[zerothinktimes,nonzerothinktimes]);
78N=N(:,[zerothinktimes,nonzerothinktimes]);
79Z=Z(:,[zerothinktimes,nonzerothinktimes]);
81 lambda=lambda(:,[zerothinktimes,nonzerothinktimes]);