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