LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_nc_sanitize.m
1%{
2%{
3 % @file pfqn_nc_sanitize.m
4 % @brief Sanitize and preprocess network parameters for NC solvers.
5%}
6%}
7
8%{
9%{
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.
22%}
23%}
24function [lambda,L,N,Z,lGremaind] = pfqn_nc_sanitize(lambda,L,N,Z,atol)
25% erase empty classes
26L(isnan(L)) = 0;
27Z(isnan(Z)) = 0;
28nnzclasses=find(N);
29L=L(:,nnzclasses);
30N=N(:,nnzclasses);
31Z=Z(:,nnzclasses);
32lambda=lambda(:,nnzclasses);
33% erase ill-defined classes
34zeroclasses=find((sum(L,1)+sum(Z,1))<atol);
35L(:,zeroclasses)=[];
36N(:,zeroclasses)=[];
37Z(:,zeroclasses)=[];
38lambda(:,zeroclasses)=[];
39%
40lGremaind= 0;
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)));
46 L(:,zerodemands)=[];
47 Z(:,zerodemands)=[];
48 N(:,zerodemands)=[];
49 lambda(:,zerodemands)=[];
50end
51% rescale demands
52Lmax = max(L,[],1); % use L, which has been santized to always be ~=0
53if isempty(Lmax)
54 Lmax = ones(1,size(Z,2));
55end
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)
61if ~isempty(Z)
62 [~,rsort] = sort(sum(Z,1),'ascend');
63 if ~isempty(L)
64 L=L(:,rsort);
65 end
66 Z=Z(:,rsort);
67 N=N(:,rsort);
68 if ~isempty(lambda)
69 lambda=lambda(:,rsort);
70 end
71end
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]);
80if ~isempty(lambda)
81 lambda=lambda(:,[zerothinktimes,nonzerothinktimes]);
82end
83end