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
24if nargin<4
25 m=1;
26end
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% initialize
40nvec=zeros(1,R);
41h=ones(2,1);
42lh=log(h) + factln(sum(nvec)+M-1) - sum(factln(nvec));
43h=exp(lh);
44scale=zeros(1,sum(N));
45% iterate
46for r=1:R
47 for Nr=1:N(r)
48 nvec(r)=nvec(r)+1;
49 if Nr==1
50 if r>1
51 P = zeros(2*(r-1),2*r);
52 r1 = r-1;
53 P(1:r1,1:r1) = eye(r1);
54 P((r1+1):2*r1,(r+1):(2*r-1)) = eye(r1);
55 h1=h'*P;
56 h1=h1';
57 h1(r)=h_1(1)*nvec(r1)/(sum(nvec)-1)/scale(nt);
58 h1(end)=h_1(r1+1)*nvec(r1)/(sum(nvec)-1)/scale(nt);
59 h=h1;
60 end
61 A = zeros(2*r);
62 DA = zeros(2*r);
63 B = zeros(2*r);
64 % 1 CE for G+
65 A(1,1) = 1;
66 A(1,2:r) = -L(1,1:r-1);
67 A(1,r+1) = -1;
68 B(1,1) = L(1,r);
69 % Class-1..(R-1) PCs for G
70 for s=1:(r-1)
71 A(1+s,r+1) = N(s);
72 A(1+s,r+1+s) = -Z(s);
73 A(1+s,1+s) = -m*L(1,s);
74 end
75 % Class-R PCs for G and Gr (r=1...R-1)
76 A(r+1:2*r,r+1:2*r) = Nr*eye(r);
77 DA(r+1:2*r,r+1:2*r) = eye(r);
78 B(r+1:2*r,1:r) = m*L(1,r)*eye(r);
79 B(r+1:2*r,r+1:2*r) = Z(r)*eye(r);
80 C = A(1:r,1:r);
81 A12 = A(1:r,r+1:2*r);
82 B1r = B(1:r,:);
83 B2r = B(r+1:2*r,:);
84 F1r = [inv(C)*B1r; 0*B2r];
85 F2r = [-C\A12*B2r; B2r];
86 end
87 h_1 = h;
88 h = (nvec(r)*F1r+F2r)*h_1/(sum(nvec)+M-1);
89 nt=sum(nvec);
90 scale(nt)=abs(sum(sort(h)));
91 h = abs(h)/scale(nt); % rescale so that |h|=1
92 end
93end
94% unscale and return the log of the normalizing constant
95lG=lG0+log(h(end-(R-1))) + factln(sum(N)+M-1) - sum(factln(N)) + N*log(Lmax)' + sum(log(scale));
96end