LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_rd.m
1%{
2%{
3 % @file pfqn_rd.m
4 % @brief Reduced Decomposition (RD) method for load-dependent networks.
5%}
6%}
7
8%{
9%{
10 % @brief Reduced Decomposition (RD) method for load-dependent networks.
11 % @fn pfqn_rd(L, N, Z, mu, options)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param mu Load-dependent rate matrix.
16 % @param options Solver options.
17 % @return lGN Logarithm of normalizing constant.
18 % @return Cgamma Gamma correction factor.
19%}
20%}
21function [lGN,Cgamma] = pfqn_rd(L,N,Z,mu,options)
22[M,R]=size(L);
23lambda=zeros(1,R);
24if sum(N)<0
25 lGN=-Inf;
26 return
27end
28if nargin<5
29 options=SolverNC.defaultOptions;
30end
31% L
32% N
33% Z
34% mu
35for ist=1:M
36 if all(mu(ist,:)==mu(ist,1)) % LI station
37 L(ist,:) = L(ist,:) / mu(ist,1);
38 mu(ist,:) = 1;
39 %isLI(i) = true;
40 end
41end
42if sum(N)==0
43 lGN=0;
44 return
45end
46gamma = ones(M,ceil(sum(N)));
47mu = mu(:,1:sum(N));
48%mu(mu==0)=Inf;
49mu(isnan(mu))=Inf;
50s = zeros(M,1);
51for ist=1:M
52 if isfinite(mu(ist,end))
53 s(ist) = min(find(abs(mu(ist,:)-mu(ist,end))<options.tol));
54 if s(ist)==0
55 s(ist) = sum(N);
56 end
57 else
58 s(ist) = sum(N);
59 end
60end
61isDelay = false(M,1);
62isLI = false(M,1);
63y = L;
64
65for ist=1:M
66 if isinf(mu(ist,s(ist)))
67 lastfinite=max(find(isfinite(mu(ist,:))));
68 s(ist) = lastfinite;
69 end
70 y(ist,:) = y(ist,:) / mu(ist,s(ist));
71end
72for ist=1:M
73 gamma(ist,:) = mu(ist,:)/mu(ist,s(ist));
74 if max(abs(mu(ist,:)-(1:sum(N)))) < options.tol
75 %isDelay(i) = true;
76 end
77end
78
79% eliminating the delays seems to produce problems
80% Z = sum([Z; L(isDelay,:)],1);
81% L(isDelay,:)=[];
82% mu(isDelay,:)=[];
83% gamma(isDelay,:)=[];
84% y(isDelay,:)=[];
85% isLI(isDelay) = [];
86% M = M - sum(isDelay);
87
88beta = ones(M,ceil(sum(N)));
89for ist=1:M
90 beta(ist,1) = gamma(ist,1) / (1-gamma(ist,1)) ;
91 for j=2:sum(N)
92 beta(ist,j) = (1-gamma(ist,j-1)) * (gamma(ist,j) / (1-gamma(ist,j)));
93 end
94end
95beta(isnan(beta))=Inf;
96
97if (all(beta==Inf))
98 options.method='default';
99 lGN = pfqn_nc(lambda,L,N,Z,options);
100 return
101else
102 Cgamma=0;
103 sld = s(s>1);
104 vmax = min(sum(sld-1),ceil(sum(N)));
105 Y = pfqn_mva(y,N,0*N); % single class model
106 rhoN = y*Y';
107 for vtot=1:vmax
108 lEN(vtot+1) = real(pfqn_gldsingle(rhoN,vtot,beta));
109 end
110
111 for vtot=0:vmax
112 EN = exp(lEN(vtot+1));
113 Cgamma = Cgamma + ((sum(N)-max(0,max(vtot-1)))/sum(N)) * EN;
114 end
115 options.method='default';
116 lGN = pfqn_nc(lambda,y,N,Z,options);
117 lGN = lGN + log(Cgamma);
118end
119end