1function [QN,UN,RN,TN,CN,XN] = solver_ctmc_avg_from_pi(sn, pivec, StateSpace, StateSpaceAggr, arvRates, depRates)
2% SOLVER_CTMC_AVG_FROM_PI Map a state distribution to mean performance metrics.
4% [QN,UN,RN,TN,CN,XN] = SOLVER_CTMC_AVG_FROM_PI(SN, PIVEC, STATESPACE,
5% STATESPACEAGGR, ARVRATES, DEPRATES)
7% Given an arbitrary probability vector PIVEC over the enumerated CTMC state
8% space of SN (rows of STATESPACE / STATESPACEAGGR), returns the per-(station,
9%
class) mean queue length QN, utilization UN, response time RN, throughput TN,
10% system response time CN and system throughput XN. The discipline-aware mapping
11%
is identical to the steady-state reduction performed by solver_ctmc_analyzer;
12% it
is factored here so that callers holding their own distribution (e.g. the
13% SolverENV state-vector analyzer, which time-averages a transient distribution)
14% can reuse it without re-solving
for the stationary vector.
16% Copyright (c) 2012-2026, Imperial College London
26probSysState = pivec(:)';
27probSysState(probSysState<GlobalConstants.Zero) = 0;
28if sum(probSysState) > 0
29 probSysState = probSysState/sum(probSysState);
31wset = 1:size(StateSpace,1);
40istSpaceShift = zeros(1,M);
43 istSpaceShift(ist) = 0;
45 istSpaceShift(ist) = istSpaceShift(ist-1) + size(sn.space{ist-1},2);
50 refsf = sn.stationToStateful(sn.refstat(k));
51 XN(k) = probSysState*arvRates(wset,refsf,k);
55 isf = sn.stationToStateful(ist);
56 ind = sn.stationToNode(ist);
58 TN(ist,k) = probSysState*depRates(wset,isf,k);
59 QN(ist,k) = probSysState*StateSpaceAggr(wset,(ist-1)*K+k);
61 if sn.nodetype(ind) ~= NodeType.Source
63 case SchedStrategy.INF
65 UN(ist,k) = QN(ist,k);
67 case {SchedStrategy.PS, SchedStrategy.DPS, SchedStrategy.GPS, SchedStrategy.LPS}
68 if isempty(sn.lldscaling) && isempty(sn.cdscaling) && ~sn_has_joint_dependence(sn)
70 if ~isempty(PH{ist}{k})
71 % There are cases where due to remove of
72 % immediate transitions or due to cutoff the
73 % utilization estimator based on arrivals or
74 % departures can be under-estimated. E.g.:
75 % UNarv_ik doesn
't work well with example_stateDependentRouting_3
76 % UNdep_ik doesn't work well with test_OQN_JMT_6
77 % Therefore, we take the maximum of the two
78 % Note: the two estimators are normally
80 UNarv_ik = probSysState*arvRates(wset,isf,k)*map_mean(PH{ist}{k})/S(ist);
81 UNdep_ik = TN(ist,k)*map_mean(PH{ist}{k})/S(ist); %
this is valid because CS in LINE
is in a separate node
82 UN(ist,k) = max(UNarv_ik,UNdep_ik);
85 else % lld/cd/ljd cases
86 ind = sn.stationToNode(ist);
89 [ni,nir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(ist)+1):(istSpaceShift(ist)+size(sn.space{ist},2))));
92 UN(ist,k) = UN(ist,k) + probSysState(st)*nir(k)*sn.schedparam(ist,k)/(nir*sn.schedparam(ist,:)
');
97 case SchedStrategy.PAS
98 % Pass-and-swap (order-independent): utilization is the
99 % time-average number of in-service jobs per class divided by
100 % the number of servers. sir already counts the positions whose
101 % marginal rate increment is positive (toMarginal PAS branch),
102 % so a single job served by multiple server types still counts
103 % as one in-service job (not 1/rate).
104 ind = sn.stationToNode(ist);
107 [~,~,sir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(ist)+1):(istSpaceShift(ist)+size(sn.space{ist},2))));
109 UN(ist,k) = UN(ist,k) + probSysState(st)*sir(k)/S(ist);
113 if isempty(sn.lldscaling) && isempty(sn.cdscaling) && ~sn_has_joint_dependence(sn)
115 if ~isempty(PH{ist}{k})
116 % There are cases where due to remove of
117 % immediate transitions or due to cutoff the
118 % utilization estimator based on arrivals or
119 % departures can be under-estimated. E.g.:
120 % UNarv_ik doesn't work well with example_stateDependentRouting_3
121 % UNdep_ik doesn
't work well with test_OQN_JMT_6
122 % Therefore, we take the maximum of the two
123 % Note: the two estimators are normally
125 UNarv_ik = probSysState*arvRates(wset,isf,k)*map_mean(PH{ist}{k})/S(ist);
126 UNdep_ik = TN(ist,k)*map_mean(PH{ist}{k})/S(ist); % this is valid because CS in LINE is in a separate node
127 UN(ist,k) = max(UNarv_ik,UNdep_ik);
130 else % lld/cd/ljd cases
131 ind = sn.stationToNode(ist);
134 [ni,~,sir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(ist)+1):(istSpaceShift(ist)+size(sn.space{ist},2))));
137 UN(ist,k) = UN(ist,k) + probSysState(st)*sir(k)/S(ist);
149 RN(ist,k) = QN(ist,k)./TN(ist,k);
154 CN(k) = NK(k)./XN(k);