4 % @brief CoMoM algorithm
for computing the normalizing constant.
8function lG=pfqn_comom(L,N,Z,atol)
11 % @brief CoMoM algorithm
for computing the normalizing constant.
12 % @fn pfqn_comom(L, N, Z, atol)
13 % @param L Service demand matrix.
14 % @param N Population vector.
15 % @param Z Think time vector.
16 % @param atol Tolerance.
17 % @
return lG Logarithm of the normalizing constant.
23% atol has no other
default in
this family; 1e-14 matches the sibling
24% pfqn_procomom. Without
this the 3-argument
form advertised in the header
25% died on an undefined atol at the Lmax rescaling below.
31 line_error(mfilename,
'pfqn_comom supports at most one queueing station (repairman models with a delay); use pfqn_ca or pfqn_recal for M>1.');
35Lmax(Lmax<atol)=Z(Lmax<atol); % unless zero
37L = L./repmat(Lmax,M,1);
38Z = Z./repmat(Lmax,M,1);
39% sort from smallest to largest
40%[~,rsort] = sort(Z,
'ascend');
43% prepare comom data structures
50lh=log(h) + factln(sum(nvec)+M-1) - sum(factln(nvec));
53matrixDim = nchoosek(M+R-1,M)*(M+1);
62 [A,B,DA]=genmatrix(L,nvec,Z,r);
66 b = B*h*nvec(r)/(sum(nvec)+M-1);
69 scale(nt)=abs(sum(sort(h)));
70 h = abs(h)/scale(nt); % rescale so that |h|=1
73% unscale and
return the log of the normalizing constant
74lG=log(h(end-(R-1))) + factln(sum(N)+M-1) - sum(factln(N)) + N*log(Lmax)
' + sum(log(scale));
76 function [A,B,DA]=genmatrix(L,N,Z,r)
78 A=zeros(nchoosek(M+R-1,M)*(M+1));
79 DA=zeros(nchoosek(M+R-1,M)*(M+1));
80 B=zeros(nchoosek(M+R-1,M)*(M+1));
84 hnnz=hashnnz(Dn(d,:),R);
90 if sum(Dn(d,(r):R-1))>0
91 % dummy rows for unused norm consts
94 col = hash(N,N-Dn(d,:),k+1);
96 if sum(Dn(d,(r+1):R-1))>0
97 col = hash(N,N-Dn(d,:),k+1);
100 er=zeros(1,R); er(r)=1;
101 col = hash(N,N-Dn(d,:)+er,k+1);
110 A(row,hash(N,N-Dn(d,:),k+1))=1;
111 A(row,hash(N,N-Dn(d,:),0+1))=-1;
113 A(row,hash(N,oner(N-Dn(d,:),s),k+1))=-L(k,s);
115 B(row,hash(N,N-Dn(d,:),k+1))=L(k,r);
121 A(row,hash(N,n,0+1))=n(s);
122 A(row,hash(N,oner(n,s),0+1))=-Z(s);
124 A(row,hash(N,oner(n,s),k+1))=-L(k,s);
133 if sum(Dn(d,(r):R-1))<=0
136 A(row,hash(N,n,0+1))=n(r);
137 DA(row,hash(N,n,0+1))=1;
138 B(row,hash(N,n,0+1))=Z(r);
140 B(row,hash(N,n,k+1))=L(k,r);
146 function val=hashnnz(dn,R)
155 function col=hash(N,n,i)
157 col=size(Dn,1)*M+matchrow(Dn,N-n);
159 col=(matchrow(Dn,N-n)-1)*M+i-1;
165 g=zeros(size(Dn,1)*(M+1),1);
172 function I=sortbynnzpos(I)
173 % sorts a set of combinations with repetition according to the number of
177 if nnzcmp(I(i,:),I(j,:))==1
186 function r=nnzcmp(i1,i2) % return 1 if i1<i2
190 r=1; % i2 has more zeros and is thus greater
192 r=0; % i1 has more zeros and is thus greater
195 if i1(j)==0 & i2(j)>0
196 r=1; % i2 has the left-most zero
198 elseif i1(j)>0 & i2(j)==0