LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_ssa_analyzer_nrm.m
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. ***
11
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.');
17end
18
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
26
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);
41else
42 % Use explicit state space generation version
43
44 % -------------------------------------------------------------------------------
45 % 1) Run the SSA/NRM simulator ---------------------------------------------------
46 % -------------------------------------------------------------------------------
47 [pi,space,depRates,sn] = solver_ssa_nrm_space(sn, options);
48 pi=pi(:)';
49
50 % -------------------------------------------------------------------------------
51 % 2) Aggregate performance indices ----------------------------------------------
52 % -------------------------------------------------------------------------------
53 % Global class throughput ---------------------------------------------------------
54 for i=1:M
55 for k = 1:K
56 refnd = sn.stationToNode(sn.refstat(k)); % reference (sink) stateful index
57 XN(k) = pi * depRates(:, (refnd-1)*K+k);
58 end
59 end
60
61 % Station‑level metrics -----------------------------------------------------------
62 rates = sn.rates;
63 for ist = 1:M
64 ind = sn.stationToNode(ist); % reference (sink) stateful index
65 for k = 1:K
66 TN(ist,k) = pi * depRates(:, (ind-1)*K+k);
67 QN(ist,k) = pi * space(:, (ind-1)*K + k);
68 end
69
70 switch sched(ist)
71 case {SchedStrategy.INF, SchedStrategy.EXT}
72 % Infinite‑server or external delay: utilisation equals mean jobs
73 UN(ist,:) = QN(ist,:);
74
75 case SchedStrategy.PS
76 for k = 1:K
77 if ~isempty(PH{ist}{k})
78 UN(ist,k) = pi * depRates(:, (ind-1)*K+k) / rates(ist,k) / S(ist);
79 end
80 end
81 end
82 end
83
84 % Response time (Little's law) & cycle time --------------------------------------
85 for k = 1:K
86 for ist = 1:M
87 if TN(ist,k) > 0
88 RN(ist,k) = QN(ist,k) / TN(ist,k);
89 else
90 RN(ist,k) = 0;
91 end
92 end
93 CN(k) = NK(k) / XN(k);
94 end
95end
96
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;
102
103tranSysState = []; % transient traces removed in this streamlined version
104tranSync = [];
105end
Definition mmt.m:92