1function [t,pit,QNt,UNt,RNt,TNt,CNt,XNt,InfGen,StateSpace,StateSpaceAggr,EventFiltration,runtime,fname] = solver_ctmc_transient_analyzer(sn, options)
2% [T,PIT,QNT,UNT,RNT,TNT,CNT,XNT,INFGEN,STATESPACE,STATESPACEAGGR,EVENTFILTRATION,RUNTIME,FNAME] = SOLVER_CTMC_TRANSIENT_ANALYZER(QN, OPTIONS)
4% Copyright (c) 2012-2026, Imperial College London
9M = sn.nstations; %number of stations
10K = sn.nclasses; %number of
classes
17line_debug(
'CTMC transient analyzer starting: nstations=%d, nclasses=%d', M, K);
19[InfGen,StateSpace,StateSpaceAggr,EventFiltration,~,depRates,sn] = solver_ctmc(sn, options); % sn
is updated with the state space
23 save([fname,
'.mat'],
'InfGen',
'StateSpace',
'StateSpaceAggr',
'EventFiltration')
24 line_printf('\nCTMC infinitesimal generator and state space saved in: ');
25 line_printf([fname, '.mat'])
31 isf = sn.nodeToStateful(ist);
32 state = [state,zeros(1,size(sn.space{isf},2)-length(sn.state{isf})),sn.state{isf}];
35pi0 = zeros(1,length(InfGen));
37state0 = matchrow(StateSpace, state);
39 line_error(mfilename,
'Initial state not contained in the state space.');
40 % state0 = matchrow(StateSpace, round(state));
41 % state = round(state);
43 % line_error(mfilename,
'Cannot recover - CTMC stopping');
46pi0(state0) = 1; % find initial state and set it to probability 1
48%
if options.timespan(1) == options.timespan(2)
49% pit = ctmc_uniformization(pi0,Q,options.timespan(1));
50% t = options.timespan(1);
52[pit,t] = ctmc_transient(InfGen,pi0,options.timespan(1),options.timespan(2),options.stiff,[],options.timestep);
54pit(pit<GlobalConstants.Zero)=0;
62 t(1) = GlobalConstants.Zero;
65 % XNt(k) = pi*arvRates(:,sn.refstat(k),k);
67 %occupancy_t = cumsum(pit.*[0;diff(t)],1)./t;
69 TNt{ist,k} = occupancy_t*depRates(:,ist,k);
70 qlenAt_t = pit*StateSpaceAggr(:,(ist-1)*K+k);
71 %QNt{i,k} = cumsum(qlenAt_t.*[0;diff(t)])./t;
72 QNt{ist,k} = qlenAt_t;
74 case SchedStrategy.INF
75 UNt{ist,k} = QNt{ist,k};
76 case {SchedStrategy.FCFS, SchedStrategy.HOL, SchedStrategy.SIRO, SchedStrategy.SEPT, SchedStrategy.LEPT, SchedStrategy.SJF}
77 if ~isempty(PH{ist}{k})
78 UNt{ist,k} = occupancy_t*min(StateSpaceAggr(:,(ist-1)*K+k),S(ist))/S(ist);
81 uik = min(StateSpaceAggr(:,(ist-1)*K+k),S(ist)) .* StateSpaceAggr(:,(ist-1)*K+k) ./ sum(StateSpaceAggr(:,((ist-1)*K+1):(ist*K)),2);
83 utilAt_t = pit * uik / S(ist);
84 %UNt{i,k} = cumsum(utilAt_t.*[0;diff(t)])./t;
85 UNt{ist,k} = utilAt_t;
86 case SchedStrategy.DPS
87 w = sn.schedparam(ist,:);
88 nik = S(ist) * w(k) * StateSpaceAggr(:,(ist-1)*K+k) ./ sum(repmat(w,size(StateSpaceAggr,1),1).*StateSpaceAggr(:,((ist-1)*K+1):(ist*K)),2);
90 UNt{ist,k} = occupancy_t*nik;
92 if ~isempty(PH{ist}{k})
93 ind = sn.stationToNode(ist);
94 line_warning(mfilename,
'Transient utilization not support yet for station %s, returning an approximation.\n',sn.nodenames{ind});
95 UNt{ist,k} = occupancy_t*min(StateSpaceAggr(:,(ist-1)*K+k),S(ist))/S(ist);
100runtime = toc(Tstart);
103% line_printf(
'\nCTMC analysis completed. Runtime: %f seconds.\n',runtime);