1function [XN,UN,QN,RN,TN,CN,tranSysState,tranSync,sn] = solver_ssa_analyzer_nrm(sn, options)
2% SOLVER_SSA_ANALYZER_NRM Performance indices from SSA/NRM simulation
3% This variant runs the next‑reaction–method SSA on the network SN and
4% returns mean throughput (XN), utilisation (UN), queue length (QN),
5% response time (RN), throughput per station (TN) and
class residence
6% time (CN). Results are based on the empirical state probabilities
7% obtained from SOLVER_SSA_NRM.
8% *** Only stations whose scheduling policy
is INF, EXT or PS are
9% supported. Any other policy triggers an error. Cache
nodes are not
10% supported in
this simplified variant. ***
12% Validate scheduling policies ---------------------------------------------------
13allowedSched = [SchedStrategy.INF, SchedStrategy.EXT, SchedStrategy.PS];
14if any(~arrayfun(@(s) any(s == allowedSched), sn.sched))
15 error('solver_ssa_analyzer_nrm:UnsupportedPolicy', ...
16 'Only SchedStrategy.INF, SchedStrategy.EXT and SchedStrategy.PS are supported.');
19% Shorthands --------------------------------------------------------------------
20M = sn.nstations; % number of stations
21K = sn.nclasses; % number of
classes
22S = sn.nservers; % server multiplicities per station
23NK = sn.njobs'; % population vector (closed chains)
24PH = sn.proc; % service‑process MAPs/PHs
25sched = sn.sched; % scheduling policies
27% Pre‑allocate performance vectors/matrices --------------------------------------
28XN = NaN(1,K); % class throughput
29UN = NaN(M,K); % utilisation
30QN = NaN(M,K); % mean jobs at station
31RN = NaN(M,K); % response time
32TN = NaN(M,K); % class throughput at station (departures)
33CN = NaN(1,K); % cycle time per class
34% -------------------------------------------------------------------------------
35% 1) Run the SSA/NRM simulator ---------------------------------------------------
36% -------------------------------------------------------------------------------
37if isfield(options, 'config') && isfield(options.config, 'state_space_gen') && ...
38 (strcmp(options.config.state_space_gen, 'none') || strcmp(options.config.state_space_gen, 'default'))
39 % Compute only stead-state mean performance indices while running nrm
40 [QN, UN, RN, TN, CN, XN, ~, sn] = solver_ssa_nrm(sn, options);
42 % Use explicit state space generation version
44 % -------------------------------------------------------------------------------
45 % 1) Run the SSA/NRM simulator ---------------------------------------------------
46 % -------------------------------------------------------------------------------
47 [pi,space,depRates,sn] = solver_ssa_nrm_space(sn, options);
50 % -------------------------------------------------------------------------------
51 % 2) Aggregate performance indices ----------------------------------------------
52 % -------------------------------------------------------------------------------
53 % Global class throughput ---------------------------------------------------------
56 refnd = sn.stationToNode(sn.refstat(k)); % reference (sink) stateful index
57 XN(k) = pi * depRates(:, (refnd-1)*K+k);
61 % Station‑level metrics -----------------------------------------------------------
64 ind = sn.stationToNode(ist); % reference (sink) stateful index
66 TN(ist,k) = pi * depRates(:, (ind-1)*K+k);
67 QN(ist,k) = pi * space(:, (ind-1)*K + k);
71 case {SchedStrategy.INF, SchedStrategy.EXT}
72 % Infinite‑server or external delay: utilisation equals mean jobs
73 UN(ist,:) = QN(ist,:);
77 if ~isempty(PH{ist}{k})
78 UN(ist,k) = pi * depRates(:, (ind-1)*K+k) / rates(ist,k) / S(ist);
84 % Response time (Little
's law) & cycle time --------------------------------------
88 RN(ist,k) = QN(ist,k) / TN(ist,k);
93 CN(k) = NK(k) / XN(k);
97% -------------------------------------------------------------------------------
98% 3) Post‑process and clean‑up ----------------------------------------------------
99% -------------------------------------------------------------------------------
100QN(isnan(QN)) = 0; UN(isnan(UN)) = 0; RN(isnan(RN)) = 0;
101XN(isnan(XN)) = 0; TN(isnan(TN)) = 0; CN(isnan(CN)) = 0;
103tranSysState = []; % transient traces removed in this streamlined version