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';
23% Apply hard cap on iter_max for stability (Python parity)
25options.iter_max = min(options.iter_max, max_iter_cap);
29 options.method = 'qli';
30 case {
'amva.qd',
'amva.qdamva',
'qdamva'}
31 options.method =
'qd';
33 options.method =
'aql';
35 options.method =
'qdaql';
37 options.method =
'lin';
39 options.method =
'qdlin';
41 options.method =
'fli';
43 options.method =
'bs';
45 options.method =
'ab';
47 options.method =
'schmidt';
48 case 'amva.schmidt-ext'
49 options.method =
'schmidt-ext';
50 case {
'default',
'amva'}
51 if (sum(Nchain)<=2 || any(Nchain<1))
52 options.method =
'qd'; % changing to bs degrades accuracy
54 if max(sn.nservers(isfinite(sn.nservers)))==1
55 options.method =
'egflin'; %
if single server model
57 options.method =
'lin'; % lin seems way worse than aql in test_LQN_8.xml
61method = options.method;
64if sn_has_homogeneous_scheduling(sn,SchedStrategy.INF)
65 options.config.multiserver = 'default';
66 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
70sourceIdx = sn.nodetype == NodeType.Source;
71queueIdx = sn.nodetype == NodeType.Queue;
72delayIdx = sn.nodetype == NodeType.Delay;
79for i=sn.nodeToStation(sourceIdx)
81 inchain = find(sn.chains(c,:));
82 if sum(sn.rates(sn.nodeToStation(sourceIdx),inchain), 'omitnan') > 0
90cond1 = sn_has_product_form_not_het_fcfs(sn);
91cond2 = ~sn_has_load_dependence(sn);
92cond3 = ~sn_has_open_classes(sn);
93if cond1 && cond2 && (cond3 || (sn_has_product_form(sn) && sn_has_open_classes(sn) && strcmpi(options.method,'lin')))
94 % we can use linearizer only if the open model
is not heterfcfs as that approximation
is not supported, so strict product-form
is required
95 [lambda,L0,N,Z0,~,nservers,V(sn.nodeToStation(queueIdx|delayIdx),:)] = sn_get_product_form_chain_params(sn);
98 switch options.config.multiserver
99 case {
'default',
'seidmann'}
101 L = L ./ repmat(nservers(:),1,C);
102 for j=1:size(L,1) % move component of queue j to the first delay
103 Z(1,:) = Z(1,:) + L0(j,:) .* (repmat(nservers(j),1,C) - 1)./ repmat(nservers(j),1,C);
106 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
112 switch options.method
113 case 'sqni' % square root non-iterative approximation
114 if sn.nstations==2 && sum(sn.sched==SchedStrategy.INF)==1
115 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),X] = pfqn_sqni(N,L,Z);
117 [Q,U,R,T,C,X,lG,totiter,method] = deal([],[],[],[],[],[],[],0,options.method);
122 [X,Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,totiter] = pfqn_bs(L,N,Z,options.tol,options.iter_max,[],sn.sched(queueIdx));
124 if sn_has_multi_server(sn)
125 line_error(mfilename,
'AQL cannot handle multi-server stations. Try with the ''default'' or ''lin'' methods.');
127 [X,Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,totiter] = pfqn_aql(L,N,Z,options.tol,options.iter_max);
129 % Akyildiz-Bolch AMVA
for multi-server networks
130 % Use L0/Z0 (original demands) since ab handles multi-server directly
131 % without needing Seidmann transformation
132 nDelays = sum(delayIdx); % Count actual delay stations, not size(Z)
134 nservers_full = [Inf*ones(nDelays,1); nservers];
136 V_full = [ones(nDelays,C); V(sn.nodeToStation(queueIdx),:)];
137 sched_full = [SchedStrategy.INF*ones(nDelays,1); sn.sched(sn.nodeToStation(queueIdx))];
139 nservers_full = nservers;
141 V_full = V(sn.nodeToStation(queueIdx),:);
142 sched_full = sn.sched(sn.nodeToStation(queueIdx));
144 [Q_tmp,U_tmp,~,~,X,totiter] = pfqn_ab_amva(D_full,N,V_full,nservers_full,sched_full,
false,
'ab');
146 Q(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:);
147 U(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:); % delay utilization = queue length
149 Q(sn.nodeToStation(queueIdx),:) = Q_tmp(nDelays+1:end,:);
150 U(sn.nodeToStation(queueIdx),:) = U_tmp(nDelays+1:end,:);
152 % Schmidt
's exact MVA for class-dependent FCFS
153 % Use L0/Z0 (original demands) since schmidt handles multi-server directly
154 % without needing Seidmann transformation
155 nDelays = sum(delayIdx); % Count actual delay stations, not size(Z)
158 S_full = [Inf*ones(nDelays,1); nservers];
159 sched_full = [SchedStrategy.INF*ones(nDelays,1); sn.sched(sn.nodeToStation(queueIdx))];
160 V_full = [ones(nDelays,C); V(sn.nodeToStation(queueIdx),:)];
164 sched_full = sn.sched(sn.nodeToStation(queueIdx));
165 V_full = V(sn.nodeToStation(queueIdx),:);
167 [X_tmp,Q_tmp,~,~,~] = pfqn_schmidt(D_full,N,S_full,sched_full,V_full);
169 Q(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:);
170 U(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:); % delay utilization = queue length
172 Q(sn.nodeToStation(queueIdx),:) = Q_tmp(nDelays+1:end,:);
174 % Compute utilization from throughput: U = X * D / nservers
175 U(sn.nodeToStation(queueIdx),:) = repmat(X,size(L0,1),1) .* L0 ./ repmat(nservers,1,C);
178 % Extended Schmidt MVA with alpha corrections
179 % Use L0/Z0 (original demands) since schmidt-ext handles multi-server directly
180 % without needing Seidmann transformation
181 nDelays = sum(delayIdx); % Count actual delay stations, not size(Z)
184 S_full = [Inf*ones(nDelays,1); nservers];
185 sched_full = [SchedStrategy.INF*ones(nDelays,1); sn.sched(sn.nodeToStation(queueIdx))];
189 sched_full = sn.sched(sn.nodeToStation(queueIdx));
191 [X_tmp,Q_tmp,~,~,~] = pfqn_schmidt_ext(D_full,N,S_full,sched_full);
193 Q(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:);
194 U(sn.nodeToStation(delayIdx),:) = Q_tmp(1:nDelays,:); % delay utilization = queue length
196 Q(sn.nodeToStation(queueIdx),:) = Q_tmp(nDelays+1:end,:);
198 % Compute utilization from throughput: U = X * D / nservers
199 U(sn.nodeToStation(queueIdx),:) = repmat(X,size(L0,1),1) .* L0 ./ repmat(nservers,1,C);
201 case {'lin
','gflin
','egflin
'}
202 % For models with joint dependence (LJD/LJCD), use solver_amvald which handles it
203 if sn_has_joint_dependence(sn)
204 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
206 elseif max(nservers)==1
207 % remove sources from L
208 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,~,X,totiter] = pfqn_linearizermx(lambda,L,N,Z,nservers,sn.sched(sn.nodeToStation(queueIdx)),options.tol,options.iter_max, options.method);
210 switch options.config.multiserver
212 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,~,X,totiter] = pfqn_conwayms(L,N,Z,nservers,sn.sched(queueIdx),options.tol,options.iter_max);
214 [Q(sn.nodeToStation(queueIdx),:),U(sn.nodeToStation(queueIdx),:),~,~,X,totiter] = pfqn_linearizermx(lambda,L,N,Z,nservers,sn.sched(sn.nodeToStation(queueIdx)),options.tol,options.iter_max, options.method);
215 case {'default', 'softmin
', 'seidmann
'}
216 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
221 switch options.config.multiserver
222 case {'conway
','erlang
','krzesinski
'}
223 options.config.multiserver = 'default';
225 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);
229 % compute performance at delay, then unapply seidmann if needed
231 % For ab/schmidt methods, Q for delays was already set correctly by the algorithm
232 % using original demands Z0. For other methods, use Seidmann-modified Z.
233 if strcmp(options.method,'ab
') || startsWith(options.method,'schmidt
')
234 Q(sn.nodeToStation(delayIdx),:) = repmat(X,sum(delayIdx),1) .* Z0;
236 Q(sn.nodeToStation(delayIdx),:) = repmat(X,sum(delayIdx),1) .* Z;
238 U(sn.nodeToStation(delayIdx),:) = Q(sn.nodeToStation(delayIdx),:);
239 switch options.config.multiserver
240 case {'default','seidmann
'}
241 % Skip Seidmann un-apply for ab and schmidt methods as it removes queue length
242 if ~strcmp(options.method,'ab
') && ~startsWith(options.method,'schmidt
')
244 if i == 1 && nservers(j)>1
245 % un-apply seidmann from first delay and move it to
247 jq = find(queueIdx,j);
248 Q(jq,:) = Q(jq,:) + (L0(j,:) .* (repmat(nservers(j),1,C) - 1)./ repmat(nservers(j),1,C)) .* X;
254 T = V .* repmat(X,M,1);
256 % For ab/schmidt methods, use original delay demands Z0
257 if strcmp(options.method,'ab
') || startsWith(options.method,'schmidt
')
263 if sn_has_class_switching(sn)
264 [Q,U,R,T,C,X] = sn_deaggregate_chain_results(sn, Lchain, [], STchain, Vchain, alpha, [], [], R, T, [], X);
267 switch options.config.multiserver
268 case {'conway
','erlang
','krzesinski
'}
269 options.config.multiserver = 'default';
271 [Q,U,R,T,C,X,lG,totiter] = solver_amvald(sn,Lchain,STchain,Vchain,alpha,Nchain,SCVchain,refstatchain,options);