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 state0 = matchrow(StateSpace, round(state));
42 line_error(mfilename,
'Initial state not contained in the state space.');
45pi0(state0) = 1; % find initial state and set it to probability 1
47%
if options.timespan(1) == options.timespan(2)
48% pit = ctmc_uniformization(pi0,Q,options.timespan(1));
49% t = options.timespan(1);
51[pit,t] = ctmc_transient(InfGen,pi0,options.timespan(1),options.timespan(2),options.stiff,[],options.timestep);
53pit(pit<GlobalConstants.Zero)=0;
61 t(1) = GlobalConstants.Zero;
64 % XNt(k) = pi*arvRates(:,sn.refstat(k),k);
66 %occupancy_t = cumsum(pit.*[0;diff(t)],1)./t;
68 TNt{ist,k} = occupancy_t*depRates(:,ist,k);
69 qlenAt_t = pit*StateSpaceAggr(:,(ist-1)*K+k);
70 %QNt{i,k} = cumsum(qlenAt_t.*[0;diff(t)])./t;
71 QNt{ist,k} = qlenAt_t;
73 case SchedStrategy.INF
74 UNt{ist,k} = QNt{ist,k};
75 case {SchedStrategy.FCFS, SchedStrategy.HOL, SchedStrategy.SIRO, SchedStrategy.SEPT, SchedStrategy.LEPT, SchedStrategy.SJF}
76 if ~isempty(PH{ist}{k})
77 UNt{ist,k} = occupancy_t*min(StateSpaceAggr(:,(ist-1)*K+k),S(ist))/S(ist);
80 uik = min(StateSpaceAggr(:,(ist-1)*K+k),S(ist)) .* StateSpaceAggr(:,(ist-1)*K+k) ./ sum(StateSpaceAggr(:,((ist-1)*K+1):(ist*K)),2);
82 utilAt_t = pit * uik / S(ist);
83 %UNt{i,k} = cumsum(utilAt_t.*[0;diff(t)])./t;
84 UNt{ist,k} = utilAt_t;
85 case SchedStrategy.DPS
86 w = sn.schedparam(ist,:);
87 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);
89 UNt{ist,k} = occupancy_t*nik;
91 if ~isempty(PH{ist}{k})
92 ind = sn.stationToNode(ist);
93 line_warning(mfilename,
'Transient utilization not support yet for station %s, returning an approximation.\n',sn.nodenames{ind});
94 UNt{ist,k} = occupancy_t*min(StateSpaceAggr(:,(ist-1)*K+k),S(ist))/S(ist);
102% line_printf(
'\nCTMC analysis completed. Runtime: %f seconds.\n',runtime);