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;
111iter = 0;
112while ~hasConverged
113 Qlast = Q;
114 % Estimate population at
115 Q_1 = Estimate(L,M,R,N_1,Z,Q,Delta,W,alpha);
116 % Forward MVA
117 [Q,W,T] = ForwardMVA(L,M,R,type,N_1,Z,Q_1);
118 if enorm(Q-Qlast)<tol || iter > maxiter
119 hasConverged = true;
120 end
121 iter = iter + 1;
122end % it
123end
124
125function [Q_1,T_1] = Estimate(~,M,R,N_1,~,Q,Delta,~,alpha)
126Q_1 = zeros(M,R);
127T_1 = zeros(R,1+R);
128for i=1:M
129 for r=1:R
130 for s=1:R
131 Ns = oner(N_1,s);
132 Q_1(i,r,1+s) = Ns(r)^alpha(r)*(Q(i,r,1+0)/N_1(r)^alpha(r) + Delta(i,r,s));
133 end
134 end
135end
136
137% This part is not used in Core so commented out
138% for r=1:R
139% Nr = oner(N_1,r);
140% for s=1:R
141% % initial guess based on balanced job bound
142% % helpful in case no stations with positive demand exists
143% T_1(s,1+r) = Nr(s) / (Z(s) + max(L(:,s))*(sum(Nr)-1));
144% for i=1:M
145% if W(i,s,1+0)>0
146% T_1(s,1+r) = Nr(s)*(Q(i,s)/N_1(s) + Delta(i,r,s))/W(i,s,1+0);
147% break;
148% end
149% end
150% end
151% end
152end
153
154function [Q,W,T] = ForwardMVA(L,M,R,type,N_1,Z,Q_1)
155W = zeros(M,R);
156T = zeros(1,R);
157Q = zeros(M,R);
158
159% Compute residence time
160for ist=1:M
161 for r=1:R
162 if type(ist) == SchedStrategy.FCFS
163 W(ist,r) = L(ist,r);
164 if L(ist,r) ~= 0
165 for s=1:R
166 W(ist,r) = W(ist,r) + L(ist,s)*Q_1(ist,s,1+r);
167 end
168 end
169 else
170 W(ist,r) = L(ist,r)*(1+sum(Q_1(ist,:,1+r)));
171 end
172
173 end
174end
175
176% Compute throughputs and qlens
177for r=1:R
178 T(r) = N_1(r) / (Z(r)+sum(W(:,r)));
179 for ist=1:M
180 Q(ist,r) = T(r) * W(ist,r);
181 end
182end
183end
184
185