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=find(Z<1e-6);
33% initialize
34nvec=zeros(1,R);
35if any(zerothinktimes)
36 nvec(zerothinktimes) = N(:,zerothinktimes);
37 lh=[];
38 % these are trivial models with a single queueing station with demands all equal to one and think time 0
39 lh(end+1,1) = (factln(sum(nvec)+m+1-1)-sum(factln(nvec)));
40 for s=find(zerothinktimes)
41 nvec_s = oner(nvec,s);
42 lh(end+1,1) = (factln(sum(nvec_s)+m+1-1)-sum(factln(nvec_s)));
43 end
44 lh(end+1,1) = (factln(sum(nvec)+m-1)-sum(factln(nvec)));
45 for s=find(zerothinktimes)
46 nvec_s = oner(nvec,s);
47 lh(end+1,1) = (factln(sum(nvec_s)+m-1)-sum(factln(nvec_s)));
48 end
49else
50 lh=zeros(2,1);
51end
52h=exp(lh);
53if length(zerothinktimes)==R
54 lGbasis = log(h);
55 lG = lG0 + log(h(end-R));
56 return
57else
58 scale = ones(1,sum(N));
59 nt = sum(nvec);
60 h_1=h;
61 %iterate
62 for r=(length(zerothinktimes)+1):R
63 for Nr=1:N(r)
64 nvec(r)=nvec(r)+1;
65 if Nr==1
66 if r> length(zerothinktimes)+1
67 hr = zeros(2*r,1);
68 hr(1:(r-1)) = h(1:(r-1));
69 hr((r+1):(2*r-1)) = h(((r-1)+1):2*(r-1));
70 h=hr;
71 % update scalings
72 if nt>0
73 h(r)=h_1(1)/scale(nt);
74 h(end)=h_1((r-1)+1)/scale(nt);
75 end
76 end
77 % CE for G+
78 A12(1,1) = -1;
79 % Class-1..(R-1) PCs for G
80 for s=1:(r-1)
81 A12(1+s,1) = N(s);
82 A12(1+s,1+s) = -Z(s);
83 end
84 % Class-R PCs
85 B2r = [m*L(1,r)*eye(r), Z(r)*eye(r)];
86 % explicit formula for inv(C)
87 iC=-eye(r)/m;
88 iC(1,:)=-1/m;
89 iC(1)=1;
90 % explicit formula for F1r
91 F1r = zeros(2*r); F1r(1,1)=1;
92 % F2r by the definition
93 F2r = [-iC*A12*B2r; B2r];
94 end
95 h_1 = h;
96 h = (F1r+F2r/nvec(r))*h_1;
97 nt = sum(nvec);
98 scale(nt) = abs(sum(sort(h)));
99 h = abs(h)/scale(nt); % rescale so that |h|=1
100 end
101 end
102
103 % unscale and return the log of the normalizing constant
104 lG = lG0 + log(h(end-(R-1))) + sum(log(scale));
105 lGbasis = log(h) + sum(log(scale));
106end
107end