1function sn = refreshRegions(self)
2% SN = REFRESHREGIONS() Populate finite capacity region information in sn struct
4% Copyright (c) 2012-2026, Imperial College London
7% Extract finite capacity region information
8% region
is a cell array of size F (number of regions)
9% region{f}
is Matrix(M, K+1) where:
10% entry (i,r) = max jobs of class r at station i in region f
11% entry (i,K+1) = global max jobs at station i in region f
12% -1 = infinite capacity
14if ~isempty(self.regions)
15 F = length(self.regions);
17 sn.region = cell(F, 1);
22 % regionrule(f, r) = DropStrategy for class r in region f
23 sn.regionrule = DropStrategy.DROP * ones(F, K); % Default to drop
24 % regionweight(f, r) = class weight for class r in region f
25 sn.regionweight = ones(F, K); % Default weight = 1.0
26 % regionsz(f, r) = class size/memory for class r in region f
27 sn.regionsz = ones(F, K); % Default size = 1
28 % regionlincon{f,1}/regionlincon{f,2} = linear constraint pair (A,b)
for region f
29 sn.regionlincon = cell(F, 2);
30 % regionmaxmem{f} = Matrix(M,1): global memory budget of region f replicated
31 % on each member station row, -1 = unbounded. Kept separate from the
32 % job-count
column so a region can cap memory while leaving jobs unbounded;
33 % mirrors the Java NetworkStruct.regionmaxmem field.
34 sn.regionmaxmem = cell(F, 1);
35% see _kb/04-networkstruct.md (refreshRegions.m)
for rationale
36 sn.regionmembers = cell(F, 1);
39 fcr = self.regions{f};
40 % Matrix with M rows (stations) and K+1 columns (K classes + 1 global)
41 regionMatrix = -1 * ones(M, K + 1); % Initialize all to infinite (-1)
42 regionMemMatrix = -1 * ones(M, 1); % Initialize all to unbounded (-1)
43 regionMemberMask = false(M, 1); % membership, independent of the caps
45 % Find which stations are in this region and set their capacities
46 for n = 1:length(fcr.
nodes)
49 if self.stations{i} == node
50 regionMemberMask(i) =
true;
51 % see _kb/04-networkstruct.md (refreshRegions.m)
for rationale
53 if r > length(fcr.classMaxJobs)
54 regionMatrix(i, r) = FiniteCapacityRegion.UNBOUNDED;
57 cap_r = fcr.classMaxJobs(r);
58 if fcr.classMaxMemory(r) ~= FiniteCapacityRegion.UNBOUNDED && fcr.classSize(r) > 0
59 memjobs = floor(fcr.classMaxMemory(r) / fcr.classSize(r));
60 if cap_r == FiniteCapacityRegion.UNBOUNDED
63 cap_r = min(cap_r, memjobs);
66 regionMatrix(i, r) = cap_r;
68 % Set global max jobs for this station in this region (
column K+1)
69 regionMatrix(i, K + 1) = fcr.globalMaxJobs;
70 % Replicate the region-global memory budget on this member row
71 regionMemMatrix(i, 1) = fcr.globalMaxMemory;
77 % Extract drop rule for each class in this region. Classes beyond
78 % the region's vectors default to WAITQ, weight 1 and size 1.
80 % fcr.dropRule
is a DropStrategy array indexed by class index
81 if r > length(fcr.dropRule)
82 sn.regionrule(f, r) = DropStrategy.WAITQ;
84 sn.regionrule(f, r) = fcr.dropRule(r);
88 % Extract class weights and sizes for this region
90 if r <= length(fcr.classWeight)
91 sn.regionweight(f, r) = fcr.classWeight(r);
93 if r <= length(fcr.classSize)
94 sn.regionsz(f, r) = fcr.classSize(r);
98 sn.region{f} = regionMatrix;
99 sn.regionmaxmem{f} = regionMemMatrix;
100 sn.regionmembers{f} = regionMemberMask;
102 % Capture the linear-constraint pair (A,b) on the same cell row
if
103 % set. A
is padded with zero columns up to K, so classes appended
104 % after the region was created stay unconstrained and engines can
105 % index A by
class without going out of bounds.
106 if ismethod(fcr, 'hasLinearConstraints') && fcr.hasLinearConstraints()
107 [linConA, linConB] = fcr.getLinearConstraints();
108 if size(linConA, 2) < K
109 linConA(:, end+1:K) = 0;
111 sn.regionlincon{f, 1} = linConA;
112 sn.regionlincon{f, 2} = linConB;
119 sn.regionweight = [];
121 sn.regionlincon = {};
122 sn.regionmaxmem = {};
123 sn.regionmembers = {};