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.
25 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.');
29Lmax(Lmax<atol)=Z(Lmax<atol); % unless zero
31L = L./repmat(Lmax,M,1);
32Z = Z./repmat(Lmax,M,1);
33% sort from smallest to largest
34%[~,rsort] = sort(Z,
'ascend');
37% prepare comom data structures
44lh=log(h) + factln(sum(nvec)+M-1) - sum(factln(nvec));
47matrixDim = nchoosek(M+R-1,M)*(M+1);
56 [A,B,DA]=genmatrix(L,nvec,Z,r);
60 b = B*h*nvec(r)/(sum(nvec)+M-1);
63 scale(nt)=abs(sum(sort(h)));
64 h = abs(h)/scale(nt); % rescale so that |h|=1
67% unscale and
return the log of
the normalizing constant
68lG=log(h(end-(R-1))) + factln(sum(N)+M-1) - sum(factln(N)) + N*log(Lmax)
' + sum(log(scale));
70 function [A,B,DA]=genmatrix(L,N,Z,r)
72 A=zeros(nchoosek(M+R-1,M)*(M+1));
73 DA=zeros(nchoosek(M+R-1,M)*(M+1));
74 B=zeros(nchoosek(M+R-1,M)*(M+1));
78 hnnz=hashnnz(Dn(d,:),R);
84 if sum(Dn(d,(r):R-1))>0
85 % dummy rows for unused norm consts
88 col = hash(N,N-Dn(d,:),k+1);
90 if sum(Dn(d,(r+1):R-1))>0
91 col = hash(N,N-Dn(d,:),k+1);
94 er=zeros(1,R); er(r)=1;
95 col = hash(N,N-Dn(d,:)+er,k+1);
104 A(row,hash(N,N-Dn(d,:),k+1))=1;
105 A(row,hash(N,N-Dn(d,:),0+1))=-1;
107 A(row,hash(N,oner(N-Dn(d,:),s),k+1))=-L(k,s);
109 B(row,hash(N,N-Dn(d,:),k+1))=L(k,r);
115 A(row,hash(N,n,0+1))=n(s);
116 A(row,hash(N,oner(n,s),0+1))=-Z(s);
118 A(row,hash(N,oner(n,s),k+1))=-L(k,s);
127 if sum(Dn(d,(r):R-1))<=0
130 A(row,hash(N,n,0+1))=n(r);
131 DA(row,hash(N,n,0+1))=1;
132 B(row,hash(N,n,0+1))=Z(r);
134 B(row,hash(N,n,k+1))=L(k,r);
140 function val=hashnnz(dn,R)
149 function col=hash(N,n,i)
151 col=size(Dn,1)*M+matchrow(Dn,N-n);
153 col=(matchrow(Dn,N-n)-1)*M+i-1;
159 g=zeros(size(Dn,1)*(M+1),1);
166 function I=sortbynnzpos(I)
167 % sorts a set of combinations with repetition according to the number of
171 if nnzcmp(I(i,:),I(j,:))==1
180 function r=nnzcmp(i1,i2) % return 1 if i1<i2
184 r=1; % i2 has more zeros and is thus greater
186 r=0; % i1 has more zeros and is thus greater
189 if i1(j)==0 & i2(j)>0
190 r=1; % i2 has the left-most zero
192 elseif i1(j)>0 & i2(j)==0