2%% Example: RNN-based estimation from queue-length traces
3% Copyright (c) 2012-2026, Imperial College London
6%% define model with multiple queues
7model = infer_quick_model_rnn(
false, ...
8 {SchedStrategy.FCFS, SchedStrategy.FCFS, SchedStrategy.FCFS}, ...
9 [[150, 30, 90]], [20, 40, 60], [100]);
11node = model.getNodes();
14%% Generate queue-length traces
15fprintf(1,
'\n=== Generating queue-length traces ===\n');
17 model_tmp = infer_quick_model_rnn(
false, ...
18 {SchedStrategy.FCFS, SchedStrategy.FCFS, SchedStrategy.FCFS}, ...
19 [[150, 30, 90]], [20, 40, 60], [100]);
20 [timeI, QN] = infer_generate_qlen_traces(model_tmp, 20);
27 if ~isa(node{i},
'Source') && ~isa(node{i},
'Sink')
28 node{i}.setService(
jobclass{1}, Exp(NaN));
33fprintf(1,
'\n=== RNN Estimator ===\n');
34options = ParamEstimator.defaultOptions;
35options.method =
'rnn';
36se = ParamEstimator(model, options);
38for n = 1:length(times)
41 for i = 1:min(3, size(QN,1))
42 ql = SampledMetric(MetricType.QLen, timeI, QN{i, 1}, node{i},
jobclass{1});
47estVal = se.estimateAt(node);
48fprintf(1,
'RNN estimated demands:\n');
49for i = 1:size(estVal, 1)
50 fprintf(1, ' Node %d: %.4f\n', i, estVal(i, 1));
54solver{1} = MVA(model);
55fprintf(1,
'\nSOLVER: %s\n', solver{1}.getName());
56AvgTable{1} = solver{1}.getAvgTable();
59%% Local helper: SSA-based queue-length trace generation
60function [timeIntervals, queueLengthMatrix] = infer_generate_qlen_traces(model, stride)
61% Use the SSA solver to generate subsampled queue-length traces
62 sn = model.getStruct();
63 nStateful = sn.nstateful;
64 jobCount = sn.nclasses;
66 solver = SolverSSA(model,
'force',
true,
'timespan', [0, Inf], ...
67 'samples', 10000,
'method',
'serial');
68 ts = solver.sampleSysAggr(10000);
71 nSamples = length(ts.t);
72 idx = 1:stride:nSamples;
73 timeIntervals = ts.t(idx);
75 avgQLengths = cell(nStateful, jobCount);
78 avgQLengths{isf, c} = ts.state{isf}(idx, c);
82 queueLengthMatrix = avgQLengths;