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 state0 = matchrow(StateSpace, round(state));
40 state = round(state);
41 if state0 == -1
42 line_error(mfilename,'Initial state not contained in the state space.');
43 end
44end
45pi0(state0) = 1; % find initial state and set it to probability 1
46
47%if options.timespan(1) == options.timespan(2)
48% pit = ctmc_uniformization(pi0,Q,options.timespan(1));
49% t = options.timespan(1);
50%else
51[pit,t] = ctmc_transient(InfGen,pi0,options.timespan(1),options.timespan(2),options.stiff,[],options.timestep);
52%end
53pit(pit<GlobalConstants.Zero)=0;
54
55QNt = cell(M,K);
56UNt = cell(M,K);
57%XNt = cell(1,K);
58TNt = cell(M,K);
59
60if t(1) == 0
61 t(1) = GlobalConstants.Zero;
62end
63for k=1:K
64 % XNt(k) = pi*arvRates(:,sn.refstat(k),k);
65 for ist=1:M
66 %occupancy_t = cumsum(pit.*[0;diff(t)],1)./t;
67 occupancy_t = pit;
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;
72 switch sched(ist)
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);
78 end
79 case SchedStrategy.PS
80 uik = min(StateSpaceAggr(:,(ist-1)*K+k),S(ist)) .* StateSpaceAggr(:,(ist-1)*K+k) ./ sum(StateSpaceAggr(:,((ist-1)*K+1):(ist*K)),2);
81 uik(isnan(uik))=0;
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);
88 nik(isnan(nik))=0;
89 UNt{ist,k} = occupancy_t*nik;
90 otherwise
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);
95 end
96 end
97 end
98end
99runtime = toc(Tstart);
100
101%if options.verbose
102% line_printf('\nCTMC analysis completed. Runtime: %f seconds.\n',runtime);
103%end
104end