4 % @brief CoMoM (Class-Oriented Method of Moments)
for finite repairman model.
10 % @brief CoMoM (Class-Oriented Method of Moments)
for finite repairman model.
11 % @fn pfqn_comomrm(L, N, Z, m, atol)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param m Replication
factor (
default: 1).
16 % @param atol Absolute tolerance for numerical computations.
17 % @return lG Logarithm of normalizing constant.
18 % @return lGbasis Logarithm of basis functions.
21function [lG,lGbasis]=pfqn_comomrm(L,N,Z,m,atol)
22% comom for a finite repairment model
25 line_error(mfilename,
'The solver accepts at most a single queueing station.')
30% Same omission as pfqn_comom: atol was read by pfqn_nc_sanitize below but
31% never defaulted, so the 3- and 4-argument forms in the header were dead.
36[~,L,N,Z,lG0] = pfqn_nc_sanitize(lambda,L,N,Z,atol);
37% R must be re-read: sanitize DROPS zero-population and zero-demand classes,
38% so the pre-sanitize R overruns the shortened Z, L and N below.
40zerothinktimes = zeros(1,R);
43 if Z(r) < GlobalConstants.FineTol
44 % see _kb/03-api-layer.md (pfqn/ family: scaling, log-domain switches, dispatch gates)
45 numZeroThinkTimes = numZeroThinkTimes + 1;
46 zerothinktimes(numZeroThinkTimes) = r;
51if numZeroThinkTimes > 0
52 for z = 1:numZeroThinkTimes
53 idx = zerothinktimes(z);
56 lh=zeros(2+2*numZeroThinkTimes,1);
58 % these are trivial models with a single queueing station with demands all equal to one and think time 0
59 lh(lhIdx,1) = (factln(sum(nvec)+m+1-1)-sum(factln(nvec)));
61 for z = 1:numZeroThinkTimes
62 s = zerothinktimes(z);
63 nvec_s = oner(nvec,s);
64 lh(lhIdx,1) = (factln(sum(nvec_s)+m+1-1)-sum(factln(nvec_s)));
67 lh(lhIdx,1) = (factln(sum(nvec)+m-1)-sum(factln(nvec)));
69 for z = 1:numZeroThinkTimes
70 s = zerothinktimes(z);
71 nvec_s = oner(nvec,s);
72 lh(lhIdx,1) = (factln(sum(nvec_s)+m-1)-sum(factln(nvec_s)));
79if numZeroThinkTimes==R
81 lG = lG0 + log(h(end-R));
84 scale = ones(1,sum(N));
88 for r=(numZeroThinkTimes+1):R
94 if r> numZeroThinkTimes+1
96 hr(1:(r-1)) = h(1:(r-1));
97 hr((r+1):(2*r-1)) = h(((r-1)+1):2*(r-1));
101 h(r)=h_1(1)/scale(nt);
102 h(end)=h_1((r-1)+1)/scale(nt);
108 % Class-1..(R-1) PCs for G
111 A12(1+s,1+s) = -Z(s);
114 B2r = [m*L(1,r)*eye(r), Z(r)*eye(r)];
115 % explicit formula for inv(C)
119 % explicit formula for F1r
120 F1r = zeros(2*r); F1r(1,1)=1;
121 % F2r by the definition
122 F2r = [-iC*A12*B2r; B2r];
125 h = (F1r+F2r/nvec(r))*h_1;
127 scale(nt) = abs(sum(sort(h)));
128 h = abs(h)/scale(nt); % rescale so that |h|=1
132 % unscale and return the log of the normalizing constant
133 lG = lG0 + log(h(end-(R-1))) + sum(log(scale));
134 lGbasis = log(h) + sum(log(scale));