LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_mna_open.m
1function [Q,U,R,T,C,X,lG,totiter] = solver_mna_open(sn, options)
2
3config = options.config;
4config.space_max = 32;
5
6K = sn.nclasses;
7rt = sn.rt;
8S = 1./sn.rates;
9scv = sn.scv; scv(isnan(scv))=0;
10
11PH = sn.proc;
12I = sn.nnodes;
13M = sn.nstations;
14C = sn.nchains;
15V = cellsum(sn.visits);
16Q = zeros(M,K);
17%QN_1 = Q+Inf;
18
19U = zeros(M,K);
20R = zeros(M,K);
21T = zeros(M,K);
22X = zeros(1,K);
23
24lambda = zeros(1,C);
25
26it = 0;
27pie = {};
28D0 = {};
29
30% get service process
31for ist=1:M
32 switch sn.sched(ist)
33 case {SchedStrategy.FCFS, SchedStrategy.INF,SchedStrategy.PS}
34 for k=1:K
35 pie{ist}{k} = map_pie(PH{ist}{k});
36 D0{ist,k} = PH{ist}{k}{1};
37 if any(isnan(D0{ist,k}))
38 D0{ist,k} = -GlobalConstants.Immediate;
39 pie{ist}{k} = 1;
40 PH{ist}{k} = map_exponential(GlobalConstants.Immediate);
41 end
42 end
43 end
44end
45
46a1 = zeros(M,K);
47a2 = zeros(M,K);
48a1_1 = a1+Inf;
49a2_1 = a2+Inf;
50d2 = zeros(M,1);
51f2 = zeros(M*K,M*K);
52for ist=1:M
53 for jst=1:M
54 if sn.nodetype(sn.stationToNode(jst)) ~= NodeType.Source
55 for r=1:K
56 for s=1:K
57 if rt((ist-1)*K+r, (jst-1)*K+s)>0
58 f2((ist-1)*K+r, (jst-1)*K+s) = 1; % C^2ij,r
59 end
60 end
61 end
62 end
63 end
64end
65lambdas_inchain = cell(1,C);
66scvs_inchain = cell(1,C);
67d2c = [];
68for c=1:C
69 inchain = sn.inchain{c};
70 sourceIdx = sn.refstat(inchain(1));
71 lambdas_inchain{c} = sn.rates(sourceIdx,inchain);
72 scvs_inchain{c} = scv(sourceIdx,inchain);
73 lambda(c) = sum(lambdas_inchain{c}(isfinite(lambdas_inchain{c})));
74 d2c(c) = qna_superpos(lambdas_inchain{c},scvs_inchain{c});
75 T(sourceIdx,inchain') = lambdas_inchain{c};
76
77end
78d2(sourceIdx)=d2c(sourceIdx,:)*lambda'/sum(lambda);
79
80%% main iteration
81
82while (max(max(abs(a1_1-a1))) > options.iter_tol || max(max(abs(a2_1-a2))) > options.iter_tol )&& it <= options.iter_max %#ok<max>
83 it = it + 1;
84 %QN_1 = Q;
85 a1_1 = a1;
86 a2_1 = a2;
87 % update throughputs at all stations
88 if it==1
89 for c=1:C
90 inchain = sn.inchain{c};
91 for m=1:M
92 T(m,inchain) = V(m,inchain) .* lambda(c);
93 end
94 end
95 end
96
97 % superposition
98 for ist=1:M
99 a1(ist,:) = 0;
100 a2(ist,:) = 0;
101 lambda_i = sum(T(ist,:));
102 for jst=1:M
103 for r=1:K
104 for s=1:K
105 a1(ist,r) = a1(ist,r) + T(jst,s)*rt((jst-1)*K+s, (ist-1)*K+r);
106 a2(ist,r) = a2(ist,r) + (1/lambda_i) * f2((jst-1)*K+s, (ist-1)*K+r)*T(jst,s)*rt((jst-1)*K+s, (ist-1)*K+r);
107 end
108 end
109 end
110 end
111
112 % update flow trhough queueing station
113 for ind=1:I
114 if sn.isstation(ind)
115 ist = sn.nodeToStation(ind);
116
117 switch sn.sched(ist)
118 case SchedStrategy.INF
119 for r=1:K
120 for s=1:K
121 d2(ist,s) = a2(ist,s);
122 end
123 end
124 for c=1:C
125 inchain = sn.inchain{c};
126 for k=inchain
127 T(ist,k) = a1(ist,k);
128 U(ist,k) = S(ist,k)*T(ist,k);
129 Q(ist,k) = T(ist,k).*S(ist,k)*V(ist,k);
130 R(ist,k) = Q(ist,k)/T(ist,k);
131 end
132 end
133 case SchedStrategy.PS
134 for c=1:C
135 inchain = sn.inchain{c};
136 for k=inchain
137 TN(ist,k) = lambda(c)*V(ist,k);
138 UN(ist,k) = S(ist,k)*TN(ist,k);
139 end
140 %Nc = sum(sn.njobs(inchain)); % closed population
141 Uden = min([1-GlobalConstants.FineTol,sum(UN(ist,:))]);
142 for k=inchain
143 %QN(ist,k) = (UN(ist,k)-UN(ist,k)^(Nc+1))/(1-Uden); % geometric bound type approximation
144 QN(ist,k) = UN(ist,k)/(1-Uden);
145 RN(ist,k) = QN(ist,k)/TN(ist,k);
146 end
147 end
148 case {SchedStrategy.FCFS}
149 mu_ist = sn.rates(ist,1:K);
150 mu_ist(isnan(mu_ist))=0;
151 rho_ist_class = a1(ist,1:K)./(GlobalConstants.FineTol+sn.rates(ist,1:K));
152 rho_ist_class(isnan(rho_ist_class))=0;
153 lambda_ist = sum(a1(ist,:));
154 mi = sn.nservers(ist);
155 rho_ist = sum(rho_ist_class) / mi;
156 if rho_ist < 1-options.tol
157
158 for k=1:K
159 mubar(ist) = lambda_ist ./ rho_ist;
160 c2(ist) = -1;
161 for r=1:K
162 if mu_ist(r)>0
163 c2(ist) = c2(ist) + a1(ist,r)/lambda_ist * (mubar(ist)/mi/mu_ist(r))^2 * (scv(ist,r)+1 );
164 end
165 end
166 end
167 d2(ist) = 1 + rho_ist^2*(c2(ist)-1)/sqrt(mi) + (1 - rho_ist^2) *(sum(a2(ist,:))-1);
168 else
169 for k=1:K
170 Q(ist,k) = sn.njobs(k);
171 end
172 d2(ist) = 1;
173 end
174 for k=1:K
175 T(ist,k) = a1(ist,k);
176 U(ist,k) = T(ist,k) * S(ist,k) /sn.nservers(ist);
177
178 end
179 end
180
181 else % not a station
182 switch sn.nodetype(ind)
183 case NodeType.Fork
184 line_error(mfilename,'Fork nodes not supported yet by QNA solver.');
185 end
186 end
187 end
188
189
190 % splitting - update flow scvs
191 for ist=1:M
192 for jst=1:M
193 if sn.nodetype(sn.stationToNode(jst)) ~= NodeType.Source
194 for r=1:K
195 for s=1:K
196 if rt((ist-1)*K+r, (jst-1)*K+s)>0
197 f2((ist-1)*K+r, (jst-1)*K+s) = 1 + rt((ist-1)*K+r, (jst-1)*K+s) * (d2(ist)-1);
198 end
199 end
200 end
201 end
202 end
203 end
204end
205
206
207for ind=1:I
208 if sn.isstation(ind)
209 ist = sn.nodeToStation(ind);
210 switch sn.sched(ist)
211 case {SchedStrategy.FCFS}
212 mu_ist = sn.rates(ist,1:K);
213 mu_ist(isnan(mu_ist))=0;
214 rho_ist_class = a1(ist,1:K)./(GlobalConstants.FineTol+sn.rates(ist,1:K));
215 rho_ist_class(isnan(rho_ist_class))=0;
216 lambda_ist = sum(a1(ist,:));
217 mi = sn.nservers(ist);
218 rho_ist = sum(rho_ist_class) / mi;
219 if rho_ist < 1-options.tol
220 for k=1:K
221 if a1(ist,k)==0
222 arri_class = map_exponential(Inf);
223 else
224 arri_class = APH.fitMeanAndSCV(1/a1(ist,k),a2(ist,k)).getProcess; % MMAP repres of arrival process for class k at node ist
225 %arri_class = Erlang.fit(1/a1(ist,k),a2(ist,k)).getProcess;
226 %arri_class = map_exponential(1/a1(ist,k));
227 arri_class = {arri_class{1},arri_class{2},arri_class{2}};
228 end
229 if k==1
230 arri_node = arri_class;
231 else
232 arri_node = mmap_super(arri_node,arri_class, 'default');
233
234 %arri_node = mmap_super_safe({arri_node,arri_class}, config.space_max, 'default'); % combine arrival process from different class
235 end
236 end
237 Qret = cell(1,K);
238 [Qret{1:K}] = MMAPPH1FCFS({arri_node{[1,3:end]}}, {pie{ist}{:}}, {D0{ist,:}}, 'ncMoms', 1);
239 Q(ist,:) = cell2mat(Qret);
240 else
241 for k=1:K
242 Q(ist,k) = sn.njobs(k);
243 end
244 end
245 for k=1:K
246 R(ist,k) = Q(ist,k) ./ T(ist,k);
247 end
248 end
249
250 end
251end
252
253C = sum(R,1);
254Q = abs(Q);
255Q(isnan(Q))=0;
256U(isnan(U))=0;
257R(isnan(R))=0;
258C(isnan(C))=0;
259X(isnan(X))=0;
260lG = 0;
261totiter = it;
262end
263
264
265function [d2]=qna_superpos(lambda,a2)
266a2 = a2(isfinite(lambda));
267lambda = lambda(isfinite(lambda));
268d2 = a2(:)'*lambda(:) / sum(lambda);
269end