LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
est_rnn_closed.m
1clear node jobclass solver AvgTable
2%% Example: RNN-based estimation from queue-length traces
3% Copyright (c) 2012-2026, Imperial College London
4% All rights reserved.
5
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]);
10
11node = model.getNodes();
12jobclass = model.classes;
13
14%% Generate queue-length traces
15fprintf(1, '\n=== Generating queue-length traces ===\n');
16for n = 1:2
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);
21 times{n} = timeI;
22 traces{n} = QN;
23end
24
25% Reset service rates
26for i = 1:length(node)
27 if ~isa(node{i}, 'Source') && ~isa(node{i}, 'Sink')
28 node{i}.setService(jobclass{1}, Exp(NaN));
29 end
30end
31
32%% Estimate with RNN
33fprintf(1, '\n=== RNN Estimator ===\n');
34options = ParamEstimator.defaultOptions;
35options.method = 'rnn';
36se = ParamEstimator(model, options);
37
38for n = 1:length(times)
39 QN = traces{n};
40 timeI = times{n};
41 for i = 1:min(3, size(QN,1))
42 ql = SampledMetric(MetricType.QLen, timeI, QN{i, 1}, node{i}, jobclass{1});
43 se.addSamples(ql);
44 end
45end
46
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));
51end
52
53%% Solve model
54solver{1} = MVA(model);
55fprintf(1, '\nSOLVER: %s\n', solver{1}.getName());
56AvgTable{1} = solver{1}.getAvgTable();
57AvgTable{1}
58
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;
65
66 solver = SolverSSA(model, 'force', true, 'timespan', [0, Inf], ...
67 'samples', 10000, 'method', 'serial');
68 ts = solver.sampleSysAggr(10000);
69
70 % Subsample by stride
71 nSamples = length(ts.t);
72 idx = 1:stride:nSamples;
73 timeIntervals = ts.t(idx);
74
75 avgQLengths = cell(nStateful, jobCount);
76 for isf = 1:nStateful
77 for c = 1:jobCount
78 avgQLengths{isf, c} = ts.state{isf}(idx, c);
79 end
80 end
81
82 queueLengthMatrix = avgQLengths;
83end