LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_ctmc_transient_analyzer.m
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)
3%
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6
7RNt=[]; CNt=[]; XNt=[];
8
9M = sn.nstations; %number of stations
10K = sn.nclasses; %number of classes
11fname = '';
12Tstart = tic;
13S = sn.nservers;
14sched = sn.sched;
15PH = sn.proc;
16
17line_debug('CTMC transient analyzer starting: nstations=%d, nclasses=%d', M, K);
18
19[InfGen,StateSpace,StateSpaceAggr,EventFiltration,~,depRates,sn] = solver_ctmc(sn, options); % sn is updated with the state space
20
21if options.keep
22 fname = lineTempName;
23 save([fname,'.mat'],'InfGen','StateSpace','StateSpaceAggr','EventFiltration')
24 line_printf('\nCTMC infinitesimal generator and state space saved in: ');
25 line_printf([fname, '.mat'])
26end
27
28state = [];
29for ist=1:sn.nnodes
30 if sn.isstateful(ist)
31 isf = sn.nodeToStateful(ist);
32 state = [state,zeros(1,size(sn.space{isf},2)-length(sn.state{isf})),sn.state{isf}];
33 end
34end
35pi0 = zeros(1,length(InfGen));
36
37state0 = matchrow(StateSpace, state);
38if state0 == -1
39 line_error(mfilename,'Initial state not contained in the state space.');
40 % state0 = matchrow(StateSpace, round(state));
41 % state = round(state);
42 % if state0 == -1
43 % line_error(mfilename,'Cannot recover - CTMC stopping');
44 % end
45end
46pi0(state0) = 1; % find initial state and set it to probability 1
47
48%if options.timespan(1) == options.timespan(2)
49% pit = ctmc_uniformization(pi0,Q,options.timespan(1));
50% t = options.timespan(1);
51%else
52[pit,t] = ctmc_transient(InfGen,pi0,options.timespan(1),options.timespan(2),options.stiff,[],options.timestep);
53%end
54pit(pit<GlobalConstants.Zero)=0;
55
56QNt = cell(M,K);
57UNt = cell(M,K);
58%XNt = cell(1,K);
59TNt = cell(M,K);
60
61if t(1) == 0
62 t(1) = GlobalConstants.Zero;
63end
64for k=1:K
65 % XNt(k) = pi*arvRates(:,sn.refstat(k),k);
66 for ist=1:M
67 %occupancy_t = cumsum(pit.*[0;diff(t)],1)./t;
68 occupancy_t = pit;
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;
73 switch sched(ist)
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);
79 end
80 case SchedStrategy.PS
81 uik = min(StateSpaceAggr(:,(ist-1)*K+k),S(ist)) .* StateSpaceAggr(:,(ist-1)*K+k) ./ sum(StateSpaceAggr(:,((ist-1)*K+1):(ist*K)),2);
82 uik(isnan(uik))=0;
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);
89 nik(isnan(nik))=0;
90 UNt{ist,k} = occupancy_t*nik;
91 otherwise
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);
96 end
97 end
98 end
99end
100runtime = toc(Tstart);
101
102%if options.verbose
103% line_printf('\nCTMC analysis completed. Runtime: %f seconds.\n',runtime);
104%end
105end