LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_egflinearizer.m
1%{
2%{
3 % @file pfqn_egflinearizer.m
4 % @brief Extended generalized fixed-point Linearizer approximation.
5%}
6%}
7
8%{
9%{
10 % @brief Extended generalized fixed-point Linearizer approximation.
11 % @fn pfqn_egflinearizer(L, N, Z, type, tol, maxiter, alpha)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector.
15 % @param type Scheduling strategy type per station.
16 % @param tol Convergence tolerance (default: 1e-8).
17 % @param maxiter Maximum number of iterations (default: 1000).
18 % @param alpha Per-class scaling exponent vector.
19 % @return Q Mean queue lengths.
20 % @return U Utilization.
21 % @return W Waiting times.
22 % @return C Cycle times.
23 % @return X System throughput.
24 % @return totiter Total iterations performed.
25%}
26%}
27function [Q,U,W,C,X,totiter] = pfqn_egflinearizer(L,N,Z,type,tol,maxiter,alpha)
28% Single-server version of linearizer
29
30if nargin<5
31 maxiter = 1000;
32end
33if nargin<4
34 tol = 1e-8;
35end
36
37[M,R]=size(L);
38if isempty(Z)
39 Z = zeros(1,R);
40end
41Z = sum(Z,1);
42if isempty(L) || all(max(L)==0)
43 X = N./Z;
44 Q = zeros(M,R);
45 U = zeros(M,R);
46 W = zeros(M,R);
47 C = zeros(1,R);
48 for r=1:R
49 for i=1:M
50 U(i,r) = X(r)*L(i,r);
51 end
52 end
53 totiter = 0;
54 return
55end
56
57% Initialize
58Q = zeros(M,R,1+R);
59Delta = zeros(M,R,R);
60for s=0:R
61 N_1 = oner(N,s);
62 [~,q] = pfqn_bs(L,N_1,Z);
63 for r=1:R
64 Q(:,r,1+s) = q(:,r);
65 end
66end
67
68totiter = 0;
69% Main loop
70for I=1:3
71 for s=0:R
72 N_1 = oner(N,s); % for k=0 it just returns N
73 % Core(N_1)
74 [Q(:,:,1+s),~,~,iter] = Core(L,M,R,N_1,Z,Q(:,:,1+s),Delta,type,tol,maxiter-totiter,alpha);
75 totiter = totiter + iter;
76 end
77 % Update_Delta
78 for i=1:M
79 for r=1:R
80 if N(r)==1
81 Q(i,:,1+r) = 0;
82 end
83 for s=1:R
84 if N(s)>1
85 Ns = oner(N,s);
86 Delta(i,r,s) = Q(i,r,1+s)/Ns(r)^alpha(r) - Q(i,r,1+0)/N(r)^alpha(r);
87 end
88 end
89 end
90 end
91end
92
93
94% Core(N)
95[Q,W,X,iter] = Core(L,M,R,N,Z,Q(:,:,1+0),Delta,type,tol,maxiter-totiter,alpha);
96totiter = totiter + iter;
97% Compute performance metrics
98U = zeros(M,R);
99for i=1:M
100 for r=1:R
101 U(i,r)=X(r)*L(i,r);
102 end
103end
104Q = Q(1:M,1:R,1+0);
105C = N./X-Z;
106end
107
108function [Q,W,T,iter] = Core(L,M,R,N_1,Z,Q,Delta,type,tol,maxiter,alpha)
109hasConverged = false;
110W = L;
111T = zeros(1,R);
112iter = 0;
113while ~hasConverged
114 Qlast = Q;
115 % Estimate population at
116 Q_1 = Estimate(L,M,R,N_1,Z,Q,Delta,W,alpha);
117 % Forward MVA
118 [Q,W,T] = ForwardMVA(L,M,R,type,N_1,Z,Q_1);
119 if enorm(Q-Qlast)<tol || iter > maxiter
120 hasConverged = true;
121 end
122 iter = iter + 1;
123end % it
124end
125
126function [Q_1,T_1] = Estimate(~,M,R,N_1,~,Q,Delta,~,alpha)
127Q_1 = zeros(M,R);
128T_1 = zeros(R,1+R);
129for i=1:M
130 for r=1:R
131 for s=1:R
132 Ns = oner(N_1,s);
133 Q_1(i,r,1+s) = Ns(r)^alpha(r)*(Q(i,r,1+0)/N_1(r)^alpha(r) + Delta(i,r,s));
134 end
135 end
136end
137
138% This part is not used in Core so commented out
139% for r=1:R
140% Nr = oner(N_1,r);
141% for s=1:R
142% % initial guess based on balanced job bound
143% % helpful in case no stations with positive demand exists
144% T_1(s,1+r) = Nr(s) / (Z(s) + max(L(:,s))*(sum(Nr)-1));
145% for i=1:M
146% if W(i,s,1+0)>0
147% T_1(s,1+r) = Nr(s)*(Q(i,s)/N_1(s) + Delta(i,r,s))/W(i,s,1+0);
148% break;
149% end
150% end
151% end
152% end
153end
154
155function [Q,W,T] = ForwardMVA(L,M,R,type,N_1,Z,Q_1)
156W = zeros(M,R);
157T = zeros(1,R);
158Q = zeros(M,R);
159
160% Compute residence time
161% Note: The PS formula W = D*(1+sum(Q)) is used for all scheduling types.
162% The FCFS correction (W = D + sum_s D_s*Q_s) requires per-visit service
163% times S = D/V, but only demands D (= V*S) are available at the chain level.
164% Using D in place of S produces incorrect results when visit ratios differ
165% across chains (e.g., self-looping classes). Since for exponential FCFS the
166% per-visit response time equals the PS formula, this is the correct approach
167% for the chain-level linearizer.
168for ist=1:M
169 for r=1:R
170 W(ist,r) = L(ist,r)*(1+sum(Q_1(ist,:,1+r)));
171 end
172end
173
174% Compute throughputs and qlens
175for r=1:R
176 T(r) = N_1(r) / (Z(r)+sum(W(:,r)));
177 for ist=1:M
178 Q(ist,r) = T(r) * W(ist,r);
179 end
180end
181end
182
183