1%% Large-scale transient fluid analysis with trajectory-based iteration (TBI)
2% This example builds a vehicle-sharing-style closed network with M
3% queueing stations and one Erlang transit delay per ordered station pair,
4% giving O(M^2) stations and, with 16 Erlang phases per delay, a fluid ODE
5% with about 1500 state variables. At
this size
the monolithic stiff fluid
6% solution (method
'closing') takes several minutes, dominated by
the
7% Jacobian factorizations,
while trajectory-based iteration (TBI) solves
8% each station cell separately against frozen inbound trajectories and
9% completes in seconds. See:
11% M. Sheldon, D. Tuncer, G. Casale,
"TBI: Transient Hierarchical
12% Modeling of Large-Scale Vehicle Sharing Systems", IEEE Transactions
13% on Intelligent Transportation Systems.
15% Each cell holds one queueing station together with its outbound transit
16% delays, mirroring
the spatial submodels of
the paper.
19M = 10; % queueing stations;
the model has M + M*(M-1) stations in total
20N = 250; % closed population (vehicles)
21kph = 16; % Erlang phases per transit delay
22Tend = 20; % transient horizon
24model = Network(
'tbi_largescale');
28 Q{i} = Queue(model, sprintf(
'Q%d',i), SchedStrategy.PS);
34 D{i,j} = Delay(model, sprintf(
'D%d_%d',i,j));
38job = ClosedClass(model,
'C1', N, Q{1});
41 Q{i}.setService(job, Erlang.fitMeanAndOrder(1/(1 + 3*rand()), 4));
44 D{i,j}.setService(job, Erlang.fitMeanAndOrder(0.2 + 2*rand(), kph));
49P = model.initRoutingMatrix;
51 pr = lambda(i,:) / sum(lambda(i,:));
54 P{1}(Q{i}, D{i,j}) = pr(j);
55 P{1}(D{i,j}, Q{j}) = 1;
62% one cell per queueing station plus its outbound transit delays
63names = cellfun(@(s) s.name, model.stations,
'UniformOutput',
false);
66 idx = find(strcmp(names, sprintf(
'Q%d',i)));
69 idx(end+1) = find(strcmp(names, sprintf(
'D%d_%d',i,j))); %#ok<AGROW>
75solver = SolverFLD(model,
'method',
'tbi',
'timespan', [0 Tend],
'stiff',
true);
76solver.options.config.tbi_cells = cells;
78AvgTable = solver.getAvgTable();
79fprintf(
'TBI solved %d stations (%d ODE variables) in %.1f seconds.\n', ...
80 model.getNumberOfStations(), M*(M-1)*kph + M*4, toc);
81AvgTable(1:M,:) % queue-length summary at
the queueing stations
83% For comparison,
the undecomposed solution of
the same model:
84% solver = SolverFLD(model,
'method',
'closing',
'timespan', [0 Tend],
'stiff', true);
85% takes several minutes on
the same machine (about 80 seconds already at
86% M=8, and beyond 10 minutes at M=12).