LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
refreshRegions.m
1function sn = refreshRegions(self)
2% SN = REFRESHREGIONS() Populate finite capacity region information in sn struct
3%
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6
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
13sn = self.sn;
14if ~isempty(self.regions)
15 F = length(self.regions);
16 sn.nregions = F;
17 sn.region = cell(F, 1);
18
19 M = sn.nstations;
20 K = sn.nclasses;
21
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);
37
38 for f = 1:F
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
44
45 % Find which stations are in this region and set their capacities
46 for n = 1:length(fcr.nodes)
47 node = fcr.nodes{n};
48 for i = 1:M
49 if self.stations{i} == node
50 regionMemberMask(i) = true;
51 % see _kb/04-networkstruct.md (refreshRegions.m) for rationale
52 for r = 1:K
53 if r > length(fcr.classMaxJobs)
54 regionMatrix(i, r) = FiniteCapacityRegion.UNBOUNDED;
55 continue;
56 end
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
61 cap_r = memjobs;
62 else
63 cap_r = min(cap_r, memjobs);
64 end
65 end
66 regionMatrix(i, r) = cap_r;
67 end
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;
72 break;
73 end
74 end
75 end
76
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.
79 for r = 1:K
80 % fcr.dropRule is a DropStrategy array indexed by class index
81 if r > length(fcr.dropRule)
82 sn.regionrule(f, r) = DropStrategy.WAITQ;
83 else
84 sn.regionrule(f, r) = fcr.dropRule(r);
85 end
86 end
87
88 % Extract class weights and sizes for this region
89 for r = 1:K
90 if r <= length(fcr.classWeight)
91 sn.regionweight(f, r) = fcr.classWeight(r);
92 end
93 if r <= length(fcr.classSize)
94 sn.regionsz(f, r) = fcr.classSize(r);
95 end
96 end
97
98 sn.region{f} = regionMatrix;
99 sn.regionmaxmem{f} = regionMemMatrix;
100 sn.regionmembers{f} = regionMemberMask;
101
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;
110 end
111 sn.regionlincon{f, 1} = linConA;
112 sn.regionlincon{f, 2} = linConB;
113 end
114 end
115else
116 sn.nregions = 0;
117 sn.region = {};
118 sn.regionrule = [];
119 sn.regionweight = [];
120 sn.regionsz = [];
121 sn.regionlincon = {};
122 sn.regionmaxmem = {};
123 sn.regionmembers = {};
124end
125self.sn = sn;
126end
Definition fjtag.m:161