1%{ @file sn_get_buffer_size.m
2 % @brief Physical buffer size of a station, in jobs
4 % @author LINE Development Team
8 % @brief Returns the number of jobs a station can hold, in service included
11 % Kendall
's K: the total occupancy bound of station IST, obtained as the
12 % tighter of the station capacity sn.cap(ist) and the per-class capacities
13 % sn.classcap(ist,:). Returns Inf when the station is unbounded. Both
14 % fields are populated by refreshCapacity, which already folds setCapacity,
15 % setClassCapacity, a finite orbit and the closed-chain population into
16 % them, so this is the single place that decides whether a buffer BINDS.
18 % Only a buffer that can actually BIND is reported. refreshCapacity derives
19 % a FINITE classcap (the chain population) for EVERY closed model, so a
20 % plain finiteness test would report a buffer at every station of every
21 % closed model; a capacity at least as large as the total population can
22 % never refuse a job and is returned as Inf. sum(njobs) is Inf as soon as
23 % one class is open, so any finite capacity reachable by an open class
28 % N = sn_get_buffer_size(sn, ist)
33 % <tr><th>Name<th>Description
34 % <tr><td>sn<td>Network structure
35 % <tr><td>ist<td>Station index
40 % <tr><th>Name<th>Description
41 % <tr><td>N<td>Buffer size in jobs, Inf if unbounded
44function N = sn_get_buffer_size(sn, ist)
46if isfield(sn, 'cap
') && ~isempty(sn.cap) && numel(sn.cap) >= ist
48 N = min(N, sn.cap(ist));
51if isfield(sn, 'classcap
') && ~isempty(sn.classcap) && size(sn.classcap, 1) >= ist
52 ccap = sn.classcap(ist, :);
53 ccap = ccap(ccap > 0); % a zero marks a class that is not served here
55 N = min(N, sum(ccap));
58if isfield(sn, 'njobs
') && ~isempty(sn.njobs)
59 totalJobs = sum(sn.njobs(:));
61 N = Inf; % declared but unreachable: the buffer can never refuse a job