LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_comomrm_orig.m
1%{
2%{
3 % @file pfqn_comomrm_orig.m
4 % @brief Original CoMoM implementation for finite repairman model.
5%}
6%}
7
8%{
9%{
10 % @brief Original CoMoM implementation for finite repairman model.
11 % @fn pfqn_comomrm_orig(L, N, Z, atol)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param atol Absolute tolerance for numerical computations.
16 % @return lG Logarithm of normalizing constant.
17%}
18%}
19function lG=pfqn_comomrm_orig(L,N,Z,atol)
20% comom for a finite repairment model
21if size(L,1)~=1
22 line_error(mfilename,'The solver accepts at most a single queueing station.')
23end
24% m is read below (A(1+s,1+s) = -m*L(1,s)) on every path, but was assigned only
25% under nargin<4, so supplying atol raised an undefined-variable error for R>1.
26m=1;
27lambda = 0*N;
28[~,L,N,Z,lG0] = pfqn_nc_sanitize(lambda,L,N,Z,atol);
29[M,R]=size(L);
30% rescale demands
31Lmax = L; % use L
32Lmax(Lmax<atol)=Z(Lmax<atol); % unless zero
33L = L./repmat(Lmax,M,1);
34Z = Z./repmat(Lmax,M,1);
35% sort from smallest to largest
36[~,rsort] = sort(Z,'ascend');
37L=L(:,rsort);
38Z=Z(:,rsort);
39% see _kb/03-api-layer.md (pfqn_nc_sanitize sort-order dependency) for rationale
40N=N(:,rsort);
41Lmax=Lmax(:,rsort);
42% initialize
43nvec=zeros(1,R);
44h=ones(2,1);
45lh=log(h) + factln(sum(nvec)+M-1) - sum(factln(nvec));
46h=exp(lh);
47scale=zeros(1,sum(N));
48% iterate
49for r=1:R
50 for Nr=1:N(r)
51 nvec(r)=nvec(r)+1;
52 if Nr==1
53 if r>1
54 P = zeros(2*(r-1),2*r);
55 r1 = r-1;
56 P(1:r1,1:r1) = eye(r1);
57 P((r1+1):2*r1,(r+1):(2*r-1)) = eye(r1);
58 h1=h'*P;
59 h1=h1';
60 h1(r)=h_1(1)*nvec(r1)/(sum(nvec)-1)/scale(nt);
61 h1(end)=h_1(r1+1)*nvec(r1)/(sum(nvec)-1)/scale(nt);
62 h=h1;
63 end
64 A = zeros(2*r);
65 DA = zeros(2*r);
66 B = zeros(2*r);
67 % 1 CE for G+
68 A(1,1) = 1;
69 A(1,2:r) = -L(1,1:r-1);
70 A(1,r+1) = -1;
71 B(1,1) = L(1,r);
72 % Class-1..(R-1) PCs for G
73 for s=1:(r-1)
74 A(1+s,r+1) = N(s);
75 A(1+s,r+1+s) = -Z(s);
76 A(1+s,1+s) = -m*L(1,s);
77 end
78 % Class-R PCs for G and Gr (r=1...R-1)
79 A(r+1:2*r,r+1:2*r) = Nr*eye(r);
80 DA(r+1:2*r,r+1:2*r) = eye(r);
81 B(r+1:2*r,1:r) = m*L(1,r)*eye(r);
82 B(r+1:2*r,r+1:2*r) = Z(r)*eye(r);
83 C = A(1:r,1:r);
84 A12 = A(1:r,r+1:2*r);
85 B1r = B(1:r,:);
86 B2r = B(r+1:2*r,:);
87 F1r = [inv(C)*B1r; 0*B2r];
88 F2r = [-C\A12*B2r; B2r];
89 end
90 h_1 = h;
91 h = (nvec(r)*F1r+F2r)*h_1/(sum(nvec)+M-1);
92 nt=sum(nvec);
93 scale(nt)=abs(sum(sort(h)));
94 h = abs(h)/scale(nt); % rescale so that |h|=1
95 end
96end
97% unscale and return the log of the normalizing constant
98lG=lG0+log(h(end-(R-1))) + factln(sum(N)+M-1) - sum(factln(N)) + N*log(Lmax)' + sum(log(scale));
99end