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, ...
14 SchedStrategy.FCFS, SchedStrategy.LCFS];
15if any(~arrayfun(@(s) any(s == allowedSched), sn.sched))
16 error('solver_ssa_analyzer_nrm:UnsupportedPolicy', ...
17 'Only SchedStrategy.INF, SchedStrategy.EXT, SchedStrategy.PS, SchedStrategy.FCFS and SchedStrategy.LCFS are supported.');
20% Shorthands --------------------------------------------------------------------
21M = sn.nstations; % number of stations
22K = sn.nclasses; % number of
classes
23S = sn.nservers; % server multiplicities per station
24NK = sn.njobs'; % population vector (closed chains)
25PH = sn.proc; % service‑process MAPs/PHs
26sched = sn.sched; % scheduling policies
28% Pre‑allocate performance vectors/matrices --------------------------------------
29XN = NaN(1,K); % class throughput
30UN = NaN(M,K); % utilisation
31QN = NaN(M,K); % mean jobs at station
32RN = NaN(M,K); % response time
33TN = NaN(M,K); % class throughput at station (departures)
34CN = NaN(1,K); % cycle time per class
35% -------------------------------------------------------------------------------
36% 1) Run the SSA/NRM simulator ---------------------------------------------------
37% -------------------------------------------------------------------------------
38if isfield(options, 'config') && isfield(options.config, 'state_space_gen') && ...
39 (strcmp(options.config.state_space_gen, 'none') || strcmp(options.config.state_space_gen, 'default'))
40 % Compute only stead-state mean performance indices while running nrm
41 [QN, UN, RN, TN, CN, XN, ~, sn] = solver_ssa_nrm(sn, options);
43 % Use explicit state space generation version
45 % -------------------------------------------------------------------------------
46 % 1) Run the SSA/NRM simulator ---------------------------------------------------
47 % -------------------------------------------------------------------------------
48 [pi,space,depRates,sn] = solver_ssa_nrm_space(sn, options);
51 % -------------------------------------------------------------------------------
52 % 2) Aggregate performance indices ----------------------------------------------
53 % -------------------------------------------------------------------------------
54 % Global class throughput ---------------------------------------------------------
57 refnd = sn.stationToNode(sn.refstat(k)); % reference (sink) stateful index
58 XN(k) = pi * depRates(:, (refnd-1)*K+k);
62 % Station‑level metrics -----------------------------------------------------------
65 ind = sn.stationToNode(ist); % reference (sink) stateful index
67 TN(ist,k) = pi * depRates(:, (ind-1)*K+k);
68 QN(ist,k) = pi * space(:, (ind-1)*K + k);
72 case {SchedStrategy.INF, SchedStrategy.EXT}
73 % Infinite‑server or external delay: utilisation equals mean jobs
74 UN(ist,:) = QN(ist,:);
76 case {SchedStrategy.PS, SchedStrategy.FCFS, SchedStrategy.LCFS}
78 if ~isempty(PH{ist}{k})
79 UN(ist,k) = pi * depRates(:, (ind-1)*K+k) / rates(ist,k) / S(ist);
85 % Response time (Little
's law) & cycle time --------------------------------------
89 RN(ist,k) = QN(ist,k) / TN(ist,k);
94 CN(k) = NK(k) / XN(k);
98% -------------------------------------------------------------------------------
99% 3) Post‑process and clean‑up ----------------------------------------------------
100% -------------------------------------------------------------------------------
101QN(isnan(QN)) = 0; UN(isnan(UN)) = 0; RN(isnan(RN)) = 0;
102XN(isnan(XN)) = 0; TN(isnan(TN)) = 0; CN(isnan(CN)) = 0;
104tranSysState = []; % transient traces removed in this streamlined version