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 % regionmembers{f} = logical(M,1), true where station i belongs to region f.
36 % Membership must be recorded explicitly because it cannot be recovered from
37 % region{f}: -1 there means "unbounded", which is indistinguishable from
38 % "not a member", so a region constrained only by regionlincon would read as
39 % empty and be silently ignored by every engine.
40 sn.regionmembers = cell(F, 1);
41
42 for f = 1:F
43 fcr = self.regions{f};
44 % Matrix with M rows (stations) and K+1 columns (K classes + 1 global)
45 regionMatrix = -1 * ones(M, K + 1); % Initialize all to infinite (-1)
46 regionMemMatrix = -1 * ones(M, 1); % Initialize all to unbounded (-1)
47 regionMemberMask = false(M, 1); % membership, independent of the caps
48
49 % Find which stations are in this region and set their capacities
50 for n = 1:length(fcr.nodes)
51 node = fcr.nodes{n};
52 for i = 1:M
53 if self.stations{i} == node
54 regionMemberMask(i) = true;
55 % Set per-class max jobs for this station in this region.
56 % A per-class memory budget classMaxMemory(r) is folded in
57 % as the equivalent job cap floor(maxMem_r/classSize_r):
58 % x_r*size_r <= maxMem_r <=> x_r <= floor(maxMem_r/size_r)
59 % for integer x_r (byte-identical to JMT's
60 % classMemoryConstraint semantics).
61 % Classes appended to the model after the region was
62 % created (e.g. by the fork-join transformation) have no
63 % entry in the region's per-class vectors: they read as
64 % unconstrained defaults.
65 for r = 1:K
66 if r > length(fcr.classMaxJobs)
67 regionMatrix(i, r) = FiniteCapacityRegion.UNBOUNDED;
68 continue;
69 end
70 cap_r = fcr.classMaxJobs(r);
71 if fcr.classMaxMemory(r) ~= FiniteCapacityRegion.UNBOUNDED && fcr.classSize(r) > 0
72 memjobs = floor(fcr.classMaxMemory(r) / fcr.classSize(r));
73 if cap_r == FiniteCapacityRegion.UNBOUNDED
74 cap_r = memjobs;
75 else
76 cap_r = min(cap_r, memjobs);
77 end
78 end
79 regionMatrix(i, r) = cap_r;
80 end
81 % Set global max jobs for this station in this region (column K+1)
82 regionMatrix(i, K + 1) = fcr.globalMaxJobs;
83 % Replicate the region-global memory budget on this member row
84 regionMemMatrix(i, 1) = fcr.globalMaxMemory;
85 break;
86 end
87 end
88 end
89
90 % Extract drop rule for each class in this region. Classes beyond
91 % the region's vectors default to WAITQ, weight 1 and size 1.
92 for r = 1:K
93 % fcr.dropRule is a DropStrategy array indexed by class index
94 if r > length(fcr.dropRule)
95 sn.regionrule(f, r) = DropStrategy.WAITQ;
96 else
97 sn.regionrule(f, r) = fcr.dropRule(r);
98 end
99 end
100
101 % Extract class weights and sizes for this region
102 for r = 1:K
103 if r <= length(fcr.classWeight)
104 sn.regionweight(f, r) = fcr.classWeight(r);
105 end
106 if r <= length(fcr.classSize)
107 sn.regionsz(f, r) = fcr.classSize(r);
108 end
109 end
110
111 sn.region{f} = regionMatrix;
112 sn.regionmaxmem{f} = regionMemMatrix;
113 sn.regionmembers{f} = regionMemberMask;
114
115 % Capture the linear-constraint pair (A,b) on the same cell row if
116 % set. A is padded with zero columns up to K, so classes appended
117 % after the region was created stay unconstrained and engines can
118 % index A by class without going out of bounds.
119 if ismethod(fcr, 'hasLinearConstraints') && fcr.hasLinearConstraints()
120 [linConA, linConB] = fcr.getLinearConstraints();
121 if size(linConA, 2) < K
122 linConA(:, end+1:K) = 0;
123 end
124 sn.regionlincon{f, 1} = linConA;
125 sn.regionlincon{f, 2} = linConB;
126 end
127 end
128else
129 sn.nregions = 0;
130 sn.region = {};
131 sn.regionrule = [];
132 sn.regionweight = [];
133 sn.regionsz = [];
134 sn.regionlincon = {};
135 sn.regionmaxmem = {};
136 sn.regionmembers = {};
137end
138self.sn = sn;
139end
Definition fjtag.m:157
Definition Station.m:245