LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
largescale_tbi.m
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:
10%
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.
14%
15% Each cell holds one queueing station together with its outbound transit
16% delays, mirroring the spatial submodels of the paper.
17
18clear model;
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
23
24model = Network('tbi_largescale');
25rng(1,'twister');
26Q = cell(1,M);
27for i = 1:M
28 Q{i} = Queue(model, sprintf('Q%d',i), SchedStrategy.PS);
29end
30D = cell(M,M);
31for i = 1:M
32 for j = 1:M
33 if i ~= j
34 D{i,j} = Delay(model, sprintf('D%d_%d',i,j));
35 end
36 end
37end
38job = ClosedClass(model, 'C1', N, Q{1});
39lambda = zeros(M,M);
40for i = 1:M
41 Q{i}.setService(job, Erlang.fitMeanAndOrder(1/(1 + 3*rand()), 4));
42 for j = 1:M
43 if i ~= j
44 D{i,j}.setService(job, Erlang.fitMeanAndOrder(0.2 + 2*rand(), kph));
45 lambda(i,j) = rand();
46 end
47 end
48end
49P = model.initRoutingMatrix;
50for i = 1:M
51 pr = lambda(i,:) / sum(lambda(i,:));
52 for j = 1:M
53 if i ~= j
54 P{1}(Q{i}, D{i,j}) = pr(j);
55 P{1}(D{i,j}, Q{j}) = 1;
56 end
57 end
58end
59model.link(P);
60model.initDefault;
61
62% one cell per queueing station plus its outbound transit delays
63names = cellfun(@(s) s.name, model.stations, 'UniformOutput', false);
64cells = cell(1, M);
65for i = 1:M
66 idx = find(strcmp(names, sprintf('Q%d',i)));
67 for j = 1:M
68 if i ~= j
69 idx(end+1) = find(strcmp(names, sprintf('D%d_%d',i,j))); %#ok<AGROW>
70 end
71 end
72 cells{i} = idx;
73end
74
75solver = SolverFLD(model, 'method', 'tbi', 'timespan', [0 Tend], 'stiff', true);
76solver.options.config.tbi_cells = cells;
77tic;
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
82
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).
Definition Station.m:245