1function [QN,UN,RN,TN,CN,XN,runtime,method,totiter,percResults] = solver_mam_analyzer(sn, options)
2% [QN,UN,RN,TN,CN,XN,RUNTIME,METHOD] = SOLVER_MAM_ANALYZER(QN, OPTIONS)
4% Copyright (c) 2012-2026, Imperial College London
9% Preserve deterministic distributions
for exact MAP/D/c analysis
10if ~isfield(options,
'config')
11 options.config = struct();
13if ~isfield(options.config, 'preserveDet')
14 options.config.preserveDet = true; % Enable exact MAP/D/c solver
17% Convert non-Markovian distributions to PH (Det preserved if preserveDet=true)
18sn = sn_nonmarkov_toph(sn, options);
20if nargin<2 || isempty(options.config) || ~isfield(options.config,'merge')
21 % Preserve existing config fields (like preserveDet) while setting defaults
22 if ~isfield(options, 'config') || isempty(options.config)
23 options.config = struct();
25 if ~isfield(options.config, 'merge')
26 options.config.merge = 'super';
28 if ~isfield(options.config, 'compress')
29 options.config.compress = 'mixture.order1';
31 if ~isfield(options.config, 'space_max')
32 options.config.space_max = 128;
36method = options.method;
37percResults = []; % Initialize as empty
41 % service distribution per class scaled by utilization used as
43 line_debug('Using dec.mmap method, calling solver_mam');
44 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam(sn, options);
45 case {
'default',
'dec.source'}
46 % Check
if network
is a valid Fork-Join topology
for FJ_codes
47 [isFJ, fjInfo] = fj_isfj(sn);
50 % Use FJ_codes
for Fork-Join analysis
51 if strcmpi(options.method,
'default')
52 line_debug('Default method: using FJ_codes for Fork-Join topology\n');
54 line_debug('Detected Fork-Join topology, using FJ_codes method');
55 [QN,UN,RN,TN,CN,XN,totiter,percResults] = solver_mam_fj(sn, options);
58 % Check if network
is a valid BMAP/PH/N/N bufferless retrial queue
59 [isRetrial, ~] = qsys_is_retrial(sn);
61 % Check if network has reneging (queue abandonment) for MAPMSG
62 isReneging = hasRenegingPatience(sn);
65 % Use BMAP/PH/N/N retrial solver
66 if strcmpi(options.method, 'default')
67 line_debug('Default method: using retrial for BMAP/PH/N/N bufferless topology\n');
69 line_debug('Detected BMAP/PH/N/N retrial topology, using retrial method');
70 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_retrial(sn, options);
73 % Use MAP/M/s+G reneging solver (MAPMSG)
74 if strcmpi(options.method, 'default')
75 line_debug('Default method: using MAPMSG for MAP/M/s+G with reneging\n');
77 line_debug('Detected reneging topology, using MAPMSG method');
78 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_retrial(sn, options);
81 % arrival process per chain rescaled by
visits at each node
82 if strcmpi(options.method, 'default')
83 line_debug('Default method: using dec.source\n');
85 line_debug('Using default/dec.source method, calling solver_mam_basic');
86 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_basic(sn, options);
87 method = 'dec.source';
91 % analyze the network with Poisson streams
92 line_debug('Using dec.poisson method with space_max=1, calling solver_mam_basic');
93 options.config.space_max = 1;
94 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_basic(sn, options);
96 if sn_is_open_model(sn)
97 line_debug('Using MNA method for open model, calling solver_mna_open');
98 [QN,UN,RN,TN,CN,XN,~,totiter] = solver_mna_open(sn, options);
99 elseif sn_is_closed_model(sn)
100 line_debug('Using MNA method for closed model, calling solver_mna_closed');
101 [QN,UN,RN,TN,CN,XN,~,totiter] = solver_mna_closed(sn, options);
103 line_error(mfilename,'The mna method in SolverMAM does not support mixed models.');
106 % Level-Dependent QBD method for single-class closed networks
107 if ~sn_is_closed_model(sn)
108 line_error(mfilename,'The ldqbd method requires a closed model.');
111 line_error(mfilename,'The ldqbd method requires a single-class model.');
113 line_debug('Using LDQBD method for closed model, calling solver_mam_ldqbd');
114 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_ldqbd(sn, options);
115 case {
'inap',
'inapplus',
'exact'}
116 % RCAT-based methods (formerly SolverAG)
117 line_debug(
'Using RCAT method: %s', options.method);
118 [QN,UN,RN,TN,CN,XN,totiter] = solver_mam_ag(sn, options);
120 line_error(mfilename,
'Unknown method: %s', options.method);
125 case SchedStrategy.EXT
126 TN(i,:) = sn.rates(i,:);
137runtime = toc(Tstart);
140function isReneging = hasRenegingPatience(sn)
141% HASRENEGINGPATIENCE Check
if model has reneging/patience configured
143% Returns
true if any queue station has reneging (ImpatienceType.RENEGING)
144% configured with a patience distribution.
148% Check
if impatienceClass field exists (ImpatienceType: RENEGING, BALKING)
149if ~isfield(sn,
'impatienceClass') || isempty(sn.impatienceClass)
153% Check
if patienceProc field exists
154if ~isfield(sn,
'patienceProc') || isempty(sn.patienceProc)
158% Check each station for reneging configuration
159for ist = 1:sn.nstations
160 for r = 1:sn.nclasses
161 if sn.impatienceClass(ist, r) == ImpatienceType.RENEGING
162 if ~isempty(sn.patienceProc{ist, r})