LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_ctmc_avg_from_pi.m
1function [QN,UN,RN,TN,CN,XN] = solver_ctmc_avg_from_pi(sn, pivec, StateSpace, StateSpaceAggr, arvRates, depRates, options)
2% SOLVER_CTMC_AVG_FROM_PI Map a state distribution to mean performance metrics.
3%
4% [QN,UN,RN,TN,CN,XN] = SOLVER_CTMC_AVG_FROM_PI(SN, PIVEC, STATESPACE,
5% STATESPACEAGGR, ARVRATES, DEPRATES)
6%
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.
15%
16% Copyright (c) 2012-2026, Imperial College London
17% All rights reserved.
18
19M = sn.nstations;
20K = sn.nclasses;
21S = sn.nservers;
22NK = sn.njobs';
23sched = sn.sched;
24PH = sn.proc;
25
26probSysState = pivec(:)';
27probSysState(probSysState<GlobalConstants.Zero) = 0;
28if sum(probSysState) > 0
29 probSysState = probSysState/sum(probSysState);
30end
31wset = 1:size(StateSpace,1);
32
33XN = NaN*zeros(1,K);
34UN = NaN*zeros(M,K);
35QN = NaN*zeros(M,K);
36RN = NaN*zeros(M,K);
37TN = NaN*zeros(M,K);
38CN = NaN*zeros(1,K);
39
40istSpaceShift = zeros(1,M);
41for ist=1:M
42 if ist==1
43 istSpaceShift(ist) = 0;
44 else
45 istSpaceShift(ist) = istSpaceShift(ist-1) + size(sn.space{ist-1},2);
46 end
47end
48
49for k=1:K
50 refsf = sn.stationToStateful(sn.refstat(k));
51 XN(k) = probSysState*arvRates(wset,refsf,k);
52end
53
54for ist=1:M
55 isf = sn.stationToStateful(ist);
56 ind = sn.stationToNode(ist);
57 for k=1:K
58 TN(ist,k) = probSysState*depRates(wset,isf,k);
59 QN(ist,k) = probSysState*StateSpaceAggr(wset,(ist-1)*K+k);
60 end
61 if sn.nodetype(ind) ~= NodeType.Source
62 % see _kb/06-solver-catalog.md (G-network signals) for rationale
63 signalLoss = ctmc_signal_lossy(sn, arvRates, probSysState, wset, isf);
64 switch sched(ist)
65 case SchedStrategy.INF
66 for k=1:K
67 UN(ist,k) = QN(ist,k);
68 end
69 case {SchedStrategy.PS, SchedStrategy.DPS, SchedStrategy.GPS, SchedStrategy.LPS}
70 if isempty(sn.lldscaling) && isempty(sn.cdscaling) && isempty(sn.jdscaling)
71 for k=1:K
72 if ~isempty(PH{ist}{k})
73 % see _kb/06-solver-catalog.md (Utilization conventions) for rationale
74 UNarv_ik = probSysState*arvRates(wset,isf,k)*map_mean(PH{ist}{k})/S(ist);
75 UNdep_ik = TN(ist,k)*map_mean(PH{ist}{k})/S(ist); % this is valid because CS in LINE is in a separate node
76 UN(ist,k) = signalLoss(k)*UNdep_ik + (1-signalLoss(k))*max(UNarv_ik,UNdep_ik);
77 end
78 end
79 else % lld/cd/ljd cases
80 % see _kb/06-solver-catalog.md (Utilization conventions) for rationale
81 ind = sn.stationToNode(ist);
82 ceff = S(ist);
83 if ~isempty(sn.lldscaling) && ist <= size(sn.lldscaling,1)
84 ceff = max(ceff, max(sn.lldscaling(ist,:)));
85 end
86 UN(ist,1:K) = 0;
87 for st = wset
88 [ni,nir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(ist)+1):(istSpaceShift(ist)+size(sn.space{ist},2))));
89 if ni>0
90 lldnow = 1;
91 if ~isempty(sn.lldscaling) && ist <= size(sn.lldscaling,1)
92 lldnow = sn.lldscaling(ist, min(max(sum(ni),1), size(sn.lldscaling,2)));
93 end
94 for k=1:K
95 UN(ist,k) = UN(ist,k) + probSysState(st)*nir(k)*sn.schedparam(ist,k)/(nir*sn.schedparam(ist,:)')*lldnow/ceff;
96 end
97 end
98 end
99 end
100 case SchedStrategy.PAS
101 % see _kb/06-solver-catalog.md (Utilization conventions) for rationale
102 ind = sn.stationToNode(ist);
103 UN(ist,1:K) = 0;
104 for st = wset
105 [~,~,sir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(ist)+1):(istSpaceShift(ist)+size(sn.space{ist},2))));
106 for k=1:K
107 UN(ist,k) = UN(ist,k) + probSysState(st)*sir(k)/S(ist);
108 end
109 end
110 otherwise
111 if isempty(sn.lldscaling) && isempty(sn.cdscaling) && isempty(sn.jdscaling)
112 for k=1:K
113 if ~isempty(PH{ist}{k})
114 % see _kb/06-solver-catalog.md (Utilization conventions) for rationale
115 UNarv_ik = probSysState*arvRates(wset,isf,k)*map_mean(PH{ist}{k})/S(ist);
116 UNdep_ik = TN(ist,k)*map_mean(PH{ist}{k})/S(ist); % this is valid because CS in LINE is in a separate node
117 UN(ist,k) = signalLoss(k)*UNdep_ik + (1-signalLoss(k))*max(UNarv_ik,UNdep_ik);
118 end
119 end
120 else % lld/cd/ljd cases
121 ind = sn.stationToNode(ist);
122 UN(ist,1:K) = 0;
123 for st = wset
124 [ni,~,sir] = State.toMarginal(sn, ind, StateSpace(st,(istSpaceShift(ist)+1):(istSpaceShift(ist)+size(sn.space{ist},2))));
125 if ni>0
126 for k=1:K
127 UN(ist,k) = UN(ist,k) + probSysState(st)*sir(k)/S(ist);
128 end
129 end
130 end
131 end
132 end
133 % see _kb/06-solver-catalog.md (G-network signals) for rationale
134 if any(signalLoss) && sched(ist) ~= SchedStrategy.INF && ...
135 isempty(sn.lldscaling) && isempty(sn.cdscaling) && isempty(sn.jdscaling)
136 UNb = ctmc_signal_busy(sn, ind, ist, sched(ist), S(ist), StateSpace, istSpaceShift, wset, probSysState);
137 UN(ist,signalLoss) = UNb(signalLoss);
138 end
139 end
140end
141
142% see _kb/06-solver-catalog.md (Utilization conventions) for rationale
143if ~isempty(sn.cdscaling) && ~any(isinf(sn.njobs))
144 for ist=1:M
145 if length(sn.cdscaling) >= ist && ~isempty(sn.cdscaling{ist})
146 for k=1:K
147 bmax = sn.cdscalingpeak(ist,k);
148 if isfinite(sn.rates(ist,k)) && sn.rates(ist,k) > 0 && bmax > 0
149 UN(ist,k) = TN(ist,k) / sn.rates(ist,k) / bmax;
150 else
151 UN(ist,k) = 0;
152 end
153 end
154 end
155 end
156end
157
158% Joint-dependence (non-product-form) utilization normalization: Util=T*S/peak
159% using the declared sn.jdscalingpeak, mirroring the class-dependence block.
160if ~isempty(sn.jdscaling) && ~any(isinf(sn.njobs))
161 for ist=1:M
162 if length(sn.jdscaling) >= ist && ~isempty(sn.jdscaling{ist})
163 for k=1:K
164 bmax = sn.jdscalingpeak(ist,k);
165 if isfinite(sn.rates(ist,k)) && sn.rates(ist,k) > 0 && bmax > 0
166 UN(ist,k) = TN(ist,k) / sn.rates(ist,k) / bmax;
167 else
168 UN(ist,k) = 0;
169 end
170 end
171 end
172 end
173end
174
175
176for k=1:K
177 for ist=1:M
178 if TN(ist,k)>0
179 RN(ist,k) = QN(ist,k)./TN(ist,k);
180 else
181 RN(ist,k)=0;
182 end
183 end
184 CN(k) = NK(k)./XN(k);
185end
186
187QN(isnan(QN))=0;
188CN(isnan(CN))=0;
189RN(isnan(RN))=0;
190UN(isnan(UN))=0;
191XN(isnan(XN))=0;
192TN(isnan(TN))=0;
193end