1function [Q,U,R,T,C,X,lG,totiter,method] = solver_amva(sn,options)
2% [Q,U,R,T,C,X,lG,ITER] = SOLVER_AMVA(SN, OPTIONS)
4% Copyright (c) 2012-2026, Imperial College London
7 options = SolverMVA.defaultOptions;
10[Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain] = sn_get_demands_chain(sn);
13if ~isfield(options.config,
'np_priority')
14 options.config.np_priority = 'default';
16if ~isfield(options.config,'multiserver')
17 options.config.multiserver = 'default';
19if ~isfield(options.config,'highvar')
20 options.config.highvar = 'default';
25 options.method = 'qli';
26 case {
'amva.qd',
'amva.qdamva',
'qdamva'}
27 options.method =
'qd';
29 options.method =
'aql';
31 options.method =
'qdaql';
33 options.method =
'lin';
35 options.method =
'qdlin';
37 options.method =
'fli';
39 options.method =
'bs';
41 options.method =
'ab';
43 options.method =
'schmidt';
44 case 'amva.schmidt-ext'
45 options.method =
'schmidt-ext';
46 case {
'default',
'amva'}
47 if (sum(Nchain)<=2 || any(Nchain<1))
48 options.method =
'qd'; % changing to bs degrades accuracy
50 if max(sn.nservers(isfinite(sn.nservers)))==1
51 options.method =
'egflin'; %
if single server model
53 options.method =
'lin'; % lin seems way worse than aql in test_LQN_8.xml
57method = options.method;
60if sn_has_homogeneous_scheduling(sn,SchedStrategy.INF)
61 options.config.multiserver = 'default';
62 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
66sourceIdx = sn.nodetype == NodeType.Source;
67queueIdx = sn.nodetype == NodeType.Queue;
68delayIdx = sn.nodetype == NodeType.Delay;
75for i=sn.nodeToStation(sourceIdx)
77 inchain = find(sn.chains(c,:));
78 if sum(sn.rates(sn.nodeToStation(sourceIdx),inchain), 'omitnan') > 0
86if sn_has_product_form_not_het_fcfs(sn) && ~sn_has_load_dependence(sn) && (~sn_has_open_classes(sn) || (sn_has_product_form(sn) && sn_has_open_classes(sn) && strcmpi(options.method,'lin')))
87 % we can use linearizer only if the open model
is not heterfcfs as that approximation
is not supported, so strict product-form
is required
88 [lambda,L0,N,Z0,~,nservers,V(sn.nodeToStation(queueIdx|delayIdx),:)] = sn_get_product_form_chain_params(sn);
91 switch options.config.multiserver
92 case {
'default',
'seidmann'}
94 L = L ./ repmat(nservers(:),1,C);
95 for j=1:size(L,1) % move component of queue j to the first delay
96 Z(1,:) = Z(1,:) + L0(j,:) .* (repmat(nservers(j),1,C) - 1)./ repmat(nservers(j),1,C);
99 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
105 switch options.method
106 case 'sqni' % square root non-iterative approximation
107 if sn.nstations==2 && sum(sn.sched==SchedStrategy.INF)==1
108 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),X] = pfqn_sqni(N,L,Z);
110 [Q,U,R,T,C,X,lG,totiter,method] = deal([],[],[],[],[],[],[],0,options.method);
115 [X,Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,totiter] = pfqn_bs(L,N,Z,options.tol,options.iter_max,[],sn.sched(queueIdx));
117 if sn_has_multi_server(sn)
118 line_error(mfilename,
'AQL cannot handle multi-server stations. Try with the ''default'' or ''lin'' methods.');
120 [X,Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,totiter] = pfqn_aql(L,N,Z,options.tol,options.iter_max);
122 % Akyildiz-Bolch AMVA
for multi-server networks
123 % Use L0/Z0 (original demands) since ab handles multi-server directly
124 % without needing Seidmann transformation
125 nDelays = sum(delayIdx); % Count actual delay stations, not size(Z)
127 nservers_full = [Inf*ones(nDelays,1); nservers];
129 V_full = [ones(nDelays,C); V(sn.nodeToStation(queueIdx),:)];
130 sched_full = [SchedStrategy.INF*ones(nDelays,1); sn.sched(sn.nodeToStation(queueIdx))];
132 nservers_full = nservers;
134 V_full = V(sn.nodeToStation(queueIdx),:);
135 sched_full = sn.sched(sn.nodeToStation(queueIdx));
137 [Q_tmp,U_tmp,~,~,X,totiter] = pfqn_ab_amva(D_full,N,V_full,nservers_full,sched_full,
false,
'ab');
139 Q(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:);
140 U(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:); % delay utilization = queue length
142 Q(sn.nodeToStation(queueIdx),:) = Q_tmp(nDelays+1:end,:);
143 U(sn.nodeToStation(queueIdx),:) = U_tmp(nDelays+1:end,:);
145 % Schmidt
's exact MVA for class-dependent FCFS
146 % Use L0/Z0 (original demands) since schmidt handles multi-server directly
147 % without needing Seidmann transformation
148 nDelays = sum(delayIdx); % Count actual delay stations, not size(Z)
151 S_full = [Inf*ones(nDelays,1); nservers];
152 sched_full = [SchedStrategy.INF*ones(nDelays,1); sn.sched(sn.nodeToStation(queueIdx))];
153 V_full = [ones(nDelays,C); V(sn.nodeToStation(queueIdx),:)];
157 sched_full = sn.sched(sn.nodeToStation(queueIdx));
158 V_full = V(sn.nodeToStation(queueIdx),:);
160 [X_tmp,Q_tmp,~,~,~] = pfqn_schmidt(D_full,N,S_full,sched_full,V_full);
162 Q(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:);
163 U(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:); % delay utilization = queue length
165 Q(sn.nodeToStation(queueIdx),:) = Q_tmp(nDelays+1:end,:);
167 % Compute utilization from throughput: U = X * D / nservers
168 U(sn.nodeToStation(queueIdx),:) = repmat(X,size(L0,1),1) .* L0 ./ repmat(nservers,1,C);
171 % Extended Schmidt MVA with alpha corrections
172 % Use L0/Z0 (original demands) since schmidt-ext handles multi-server directly
173 % without needing Seidmann transformation
174 nDelays = sum(delayIdx); % Count actual delay stations, not size(Z)
177 S_full = [Inf*ones(nDelays,1); nservers];
178 sched_full = [SchedStrategy.INF*ones(nDelays,1); sn.sched(sn.nodeToStation(queueIdx))];
182 sched_full = sn.sched(sn.nodeToStation(queueIdx));
184 [X_tmp,Q_tmp,~,~,~] = pfqn_schmidt_ext(D_full,N,S_full,sched_full);
186 Q(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:);
187 U(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:); % delay utilization = queue length
189 Q(sn.nodeToStation(queueIdx),:) = Q_tmp(nDelays+1:end,:);
191 % Compute utilization from throughput: U = X * D / nservers
192 U(sn.nodeToStation(queueIdx),:) = repmat(X,size(L0,1),1) .* L0 ./ repmat(nservers,1,C);
194 case {'lin
','gflin
','egflin
'}
195 % For models with joint dependence (LJD/LJCD), use solver_amvald which handles it
196 if sn_has_joint_dependence(sn)
197 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
199 elseif max(nservers)==1
200 % remove sources from L
201 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,~,X,totiter] = pfqn_linearizermx(lambda,L,N,Z,nservers,sn.sched(sn.nodeToStation(queueIdx | delayIdx)),options.tol,options.iter_max, options.method);
203 switch options.config.multiserver
205 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,~,X,totiter] = pfqn_conwayms(L,N,Z,nservers,sn.sched(queueIdx),options.tol,options.iter_max);
207 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,~,X,totiter] = pfqn_linearizermx(lambda,L,N,Z,nservers,sn.sched(sn.nodeToStation(queueIdx | delayIdx)),options.tol,options.iter_max, options.method);
208 case {'default', 'softmin
', 'seidmann
'}
209 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
214 switch options.config.multiserver
215 case {'conway
','erlang
','krzesinski
'}
216 options.config.multiserver = 'default';
218 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
222 % compute performance at delay, then unapply seidmann if needed
224 % For ab/schmidt methods, Q for delays was already set correctly by the algorithm
225 % using original demands Z0. For other methods, use Seidmann-modified Z.
226 if strcmp(options.method,'ab
') || startsWith(options.method,'schmidt
')
227 Q(sn.nodeToStation(delayIdx),:) = repmat(X,sum(delayIdx),1) .* Z0;
229 Q(sn.nodeToStation(delayIdx),:) = repmat(X,sum(delayIdx),1) .* Z;
231 U(sn.nodeToStation(delayIdx),:) = Q(sn.nodeToStation(delayIdx),:);
232 switch options.config.multiserver
233 case {'default','seidmann
'}
234 % Skip Seidmann un-apply for ab and schmidt methods as it removes queue length
235 if ~strcmp(options.method,'ab
') && ~startsWith(options.method,'schmidt
')
237 if i == 1 && nservers(j)>1
238 % un-apply seidmann from first delay and move it to
240 jq = find(queueIdx,j);
241 Q(jq,:) = Q(jq,:) + (L0(j,:) .* (repmat(nservers(j),1,C) - 1)./ repmat(nservers(j),1,C)) .* X;
247 T = V .* repmat(X,M,1);
249 % For ab/schmidt methods, use original delay demands Z0
250 if strcmp(options.method,'ab
') || startsWith(options.method,'schmidt
')
256 if sn_has_class_switching(sn)
257 [Q,U,R,T,C,X] = sn_deaggregate_chain_results(sn, Lchain, [], STchain, Vchain, alpha, [], [], R, T, [], X);
260 switch options.config.multiserver
261 case {'conway
','erlang
','krzesinski
'}
262 options.config.multiserver = 'default';
264 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);