1function [runtime, tranSysState, tranSync] = runAnalyzer(self, options)
2% [RUNTIME, TRANSYSSTATE] = RUNANALYZER()
4% Run the DES solver on the queueing network model.
5% For LayeredNetwork models, use SolverLDES from line-apps.
9 options = self.getOptions;
11self.runAnalyzerChecks(options);
12Solver.resetRandomGeneratorSeed(options.seed);
14line_debug(
'DES solver starting: lang=%s, samples=%d, seed=%d', options.lang, options.samples, options.seed);
19% Check
if confidence intervals are requested
20[confintEnabled, confintLevel] = Solver.parseConfInt(options.confint);
24 line_debug(
'Default method: using Java DES discrete-event simulation\n');
25 line_debug(
'Using Java DES backend');
26 % Convert model to Java
27 jmodel = LINE2JLINE(self.model);
29 % Create Java solver with DES-specific options via JLINE wrapper
30 jsolver = JLINE.SolverDES(jmodel, options);
32 % Regular Network analysis
33 [runtime] = runNetworkAnalyzer(self, jmodel, jsolver, confintEnabled, options);
35 line_error(mfilename,
'SolverDES currently only supports Java backend. Use options.lang = ''java''.');
41function [runtime] = runNetworkAnalyzer(self, jmodel, jsolver, confintEnabled, options)
42% RUNNETWORKANALYZER Run DES analysis
for regular Network models
44M = jmodel.getNumberOfStations;
45R = jmodel.getNumberOfClasses;
47% Check
if this is transient analysis
48isTransient = isfield(options,
'timespan') && length(options.timespan) >= 2 && ...
49 isfinite(options.timespan(2));
52 % Run transient analysis directly
53 runTransientAnalyzer(self, jsolver, M, R, options);
54 runtime = 0; % Runtime tracked inside transient analyzer
58% Steady-state analysis
59[QN, UN, RN, WN, AN, TN] = JLINE.arrayListToResults(jsolver.getAvgTable(
true));
61CN = JLINE.from_jline_matrix(jsolver.getAvgSysRespT());
62XN = JLINE.from_jline_matrix(jsolver.getAvgSysTput());
63runtime = jsolver.result.runtime;
64QN = reshape(QN
', R, M)';
65UN = reshape(UN
', R, M)';
66RN = reshape(RN
', R, M)';
67TN = reshape(TN
', R, M)';
68WN = reshape(WN
', R, M)';
69AN = reshape(AN
', R, M)';
71% Extract FCR metrics and append to result matrices
72sn = self.model.getStruct;
75 result = jsolver.result;
76 isValidMatrix = @(x) ~isempty(x) && isa(x,
'jline.util.matrix.Matrix');
77 if isValidMatrix(result.QNfcr)
78 QNfcr = JLINE.from_jline_matrix(result.QNfcr);
79 UNfcr = JLINE.from_jline_matrix(result.UNfcr);
80 RNfcr = JLINE.from_jline_matrix(result.RNfcr);
81 TNfcr = JLINE.from_jline_matrix(result.TNfcr);
82 WNfcr = JLINE.from_jline_matrix(result.WNfcr);
83 % ANfcr
is NaN for FCR (not applicable)
85 % Append FCR rows to station metrics
95% Print samples like SSA does
97 line_printf('DES samples: %8d\n', options.samples);
100self.setAvgResults(QN, UN, RN, TN, AN, WN, CN, XN, runtime, options.method, options.samples);
102% Extract confidence intervals from Java solver results
104 result = jsolver.result;
105 % Helper to check for non-null Java objects
106 isValidMatrix = @(x) ~isempty(x) && isa(x, 'jline.util.matrix.Matrix');
107 if isValidMatrix(result.QNCI)
108 QNCI = JLINE.from_jline_matrix(result.QNCI);
109 QNCI = reshape(QNCI', R, M)';
113 if isValidMatrix(result.UNCI)
114 UNCI = JLINE.from_jline_matrix(result.UNCI);
115 UNCI = reshape(UNCI', R, M)';
119 if isValidMatrix(result.RNCI)
120 RNCI = JLINE.from_jline_matrix(result.RNCI);
121 RNCI = reshape(RNCI', R, M)';
125 if isValidMatrix(result.TNCI)
126 TNCI = JLINE.from_jline_matrix(result.TNCI);
127 TNCI = reshape(TNCI', R, M)';
131 if isValidMatrix(result.ANCI)
132 ANCI = JLINE.from_jline_matrix(result.ANCI);
133 ANCI = reshape(ANCI', R, M)';
137 if isValidMatrix(result.WNCI)
138 WNCI = JLINE.from_jline_matrix(result.WNCI);
139 WNCI = reshape(WNCI', R, M)';
144 self.setAvgResultsCI(QNCI, UNCI, RNCI, TNCI, ANCI, WNCI, [], []);
149function runTransientAnalyzer(self, jsolver, Mjava, R, options)
150% RUNTRANSIENTANALYZER Run transient analysis for DES
154% Get MATLAB model structure for correct station count
155sn = self.model.getStruct;
156M = sn.nstations; % Use MATLAB station count for cell arrays
158% Run transient analysis on Java side
160result = jsolver.result;
163% Check if transient results are available (result.QNt
is a Java 2D array)
164if ~isempty(result.QNt) && ~isempty(result.t)
165 % Get number of time points
166 Tmax = result.t.length();
168 % Convert Java transient results to MATLAB format
169 % result.QNt(ist,r)
is a Matrix(numTimePoints, 2) with columns [value, time]
170 % Use MATLAB station count for cell arrays so getTranAvg can index correctly
173 RNt = cell(M, R); % Not computed by DES, will be empty
178 % Initialize all cells to NaN
188 % Extract data from Java results (indexed by Java station count)
191 % Queue length transient
193 jmatrix = result.QNt(ist, r);
194 if ~isempty(jmatrix) && jmatrix.getNumRows() > 0
195 nRows = jmatrix.getNumRows();
196 matData = NaN(nRows, 2);
198 matData(p, 1) = jmatrix.get(p-1, 0); % value
199 matData(p, 2) = jmatrix.get(p-1, 1); % time
201 QNt{ist, r} = matData;
209 % Utilization transient
211 jmatrix = result.UNt(ist, r);
212 if ~isempty(jmatrix) && jmatrix.getNumRows() > 0
213 nRows = jmatrix.getNumRows();
214 matData = NaN(nRows, 2);
216 matData(p, 1) = jmatrix.get(p-1, 0); % value
217 matData(p, 2) = jmatrix.get(p-1, 1); % time
219 UNt{ist, r} = matData;
227 % Throughput transient
229 jmatrix = result.TNt(ist, r);
230 if ~isempty(jmatrix) && jmatrix.getNumRows() > 0
231 nRows = jmatrix.getNumRows();
232 matData = NaN(nRows, 2);
234 matData(p, 1) = jmatrix.get(p-1, 0); % value
235 matData(p, 2) = jmatrix.get(p-1, 1); % time
237 TNt{ist, r} = matData;
245 % Response time transient not computed by DES
250 % CNt and XNt not computed
for transient
256 % Store transient results
257 self.setTranAvgResults(QNt, UNt, RNt, TNt, CNt, XNt, runtime);
259 % Also compute and store steady-state estimates from
final transient values
271 if ~isscalar(QNt{ist, r}) && ~isnan(QNt{ist, r}(end, 1))
272 QN(ist, r) = QNt{ist, r}(end, 1);
274 if ~isscalar(UNt{ist, r}) && ~isnan(UNt{ist, r}(end, 1))
275 UN(ist, r) = UNt{ist, r}(end, 1);
277 if ~isscalar(TNt{ist, r}) && ~isnan(TNt{ist, r}(end, 1))
278 TN(ist, r) = TNt{ist, r}(end, 1);
283 self.setAvgResults(QN, UN, RN, TN, AN, WN, CN, XN, runtime, options.method, 0);
287% Print verbose output
if requested
289 line_printf(
'DES transient analysis complete, timespan = [%g, %g]\n', ...
290 options.timespan(1), options.timespan(2));