LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_comomrm.m
1%{
2%{
3 % @file pfqn_comomrm.m
4 % @brief CoMoM (Convolution Method of Moments) for finite repairman model.
5%}
6%}
7
8%{
9%{
10 % @brief CoMoM (Convolution 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.
19%}
20%}
21function [lG,lGbasis]=pfqn_comomrm(L,N,Z,m,atol)
22% comom for a finite repairment model
23[M,R]=size(L);
24if M~=1
25 line_error(mfilename,'The solver accepts at most a single queueing station.')
26end
27if nargin<4
28 m=1;
29end
30lambda = 0*N;
31[~,L,N,Z,lG0] = pfqn_nc_sanitize(lambda,L,N,Z,atol);
32zerothinktimes = zeros(1,R);
33numZeroThinkTimes = 0;
34for r = 1:R
35 if Z(r) < 1e-6
36 numZeroThinkTimes = numZeroThinkTimes + 1;
37 zerothinktimes(numZeroThinkTimes) = r;
38 end
39end
40% initialize
41nvec=zeros(1,R);
42if numZeroThinkTimes > 0
43 for z = 1:numZeroThinkTimes
44 idx = zerothinktimes(z);
45 nvec(idx) = N(idx);
46 end
47 lh=zeros(2+2*numZeroThinkTimes,1);
48 lhIdx = 1;
49 % these are trivial models with a single queueing station with demands all equal to one and think time 0
50 lh(lhIdx,1) = (factln(sum(nvec)+m+1-1)-sum(factln(nvec)));
51 lhIdx = lhIdx + 1;
52 for z = 1:numZeroThinkTimes
53 s = zerothinktimes(z);
54 nvec_s = oner(nvec,s);
55 lh(lhIdx,1) = (factln(sum(nvec_s)+m+1-1)-sum(factln(nvec_s)));
56 lhIdx = lhIdx + 1;
57 end
58 lh(lhIdx,1) = (factln(sum(nvec)+m-1)-sum(factln(nvec)));
59 lhIdx = lhIdx + 1;
60 for z = 1:numZeroThinkTimes
61 s = zerothinktimes(z);
62 nvec_s = oner(nvec,s);
63 lh(lhIdx,1) = (factln(sum(nvec_s)+m-1)-sum(factln(nvec_s)));
64 lhIdx = lhIdx + 1;
65 end
66else
67 lh=zeros(2,1);
68end
69h=exp(lh);
70if numZeroThinkTimes==R
71 lGbasis = log(h);
72 lG = lG0 + log(h(end-R));
73 return
74else
75 scale = ones(1,sum(N));
76 nt = sum(nvec);
77 h_1=h;
78 %iterate
79 for r=(numZeroThinkTimes+1):R
80 F1r = zeros(2*r);
81 F2r = zeros(2*r);
82 for Nr=1:N(r)
83 nvec(r)=nvec(r)+1;
84 if Nr==1
85 if r> numZeroThinkTimes+1
86 hr = zeros(2*r,1);
87 hr(1:(r-1)) = h(1:(r-1));
88 hr((r+1):(2*r-1)) = h(((r-1)+1):2*(r-1));
89 h=hr;
90 % update scalings
91 if nt>0
92 h(r)=h_1(1)/scale(nt);
93 h(end)=h_1((r-1)+1)/scale(nt);
94 end
95 end
96 % CE for G+
97 A12 = zeros(r);
98 A12(1,1) = -1;
99 % Class-1..(R-1) PCs for G
100 for s=1:(r-1)
101 A12(1+s,1) = N(s);
102 A12(1+s,1+s) = -Z(s);
103 end
104 % Class-R PCs
105 B2r = [m*L(1,r)*eye(r), Z(r)*eye(r)];
106 % explicit formula for inv(C)
107 iC=-eye(r)/m;
108 iC(1,:)=-1/m;
109 iC(1)=1;
110 % explicit formula for F1r
111 F1r = zeros(2*r); F1r(1,1)=1;
112 % F2r by the definition
113 F2r = [-iC*A12*B2r; B2r];
114 end
115 h_1 = h;
116 h = (F1r+F2r/nvec(r))*h_1;
117 nt = sum(nvec);
118 scale(nt) = abs(sum(sort(h)));
119 h = abs(h)/scale(nt); % rescale so that |h|=1
120 end
121 end
122
123 % unscale and return the log of the normalizing constant
124 lG = lG0 + log(h(end-(R-1))) + sum(log(scale));
125 lGbasis = log(h) + sum(log(scale));
126end
127end