LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ClassServiceMapping.m
1classdef ClassServiceMapping < opt.DecisionVariable
2 % ClassServiceMapping Optimize the class-to-station mapping by rerouting a
3 % job class through a selected candidate station and bypassing the others,
4 % preserving default routing of every other class. Mirrors native-Python
5 % ClassServiceMapping.
6
7 properties
9 stations % cell array of Station
10 end
11
12 methods
13 function obj = ClassServiceMapping(jobclass, stations, name)
14 if nargin < 3 || isempty(name)
15 name = [jobclass.getName() '_mapping'];
16 end
17 obj@opt.DecisionVariable(name);
18 obj.jobclass = jobclass;
19 obj.stations = stations;
20 end
21
22 function c = getJobClass(obj), c = obj.jobclass; end
23 function s = getStations(obj), s = obj.stations; end
24 function b = getBounds(obj), b = opt.DecisionVariable.unitBounds(1); end
25
26 function v = decode(obj, x)
27 n = numel(obj.stations);
28 idx = floor(x(1) * n);
29 v = min(idx, n - 1); % 0-based index
30 end
31
32 function apply(obj, model, value)
33 if isempty(obj.stations), return; end
34 v = min(max(value, 0), numel(obj.stations) - 1);
35
36 nodes = model.getNodes();
37 n = numel(nodes);
38 conn = opt.DecisionVariable.connectionMatrix(model);
39
40 selectedName = obj.stations{v + 1}.getName();
41 blocked = [];
42 for k = 1:numel(obj.stations)
43 if ~strcmp(obj.stations{k}.getName(), selectedName)
44 idx = opt.DecisionVariable.indexOfNode(nodes, obj.stations{k}.getName());
45 if idx > 0, blocked(end+1) = idx; end %#ok<AGROW>
46 end
47 end
48
49 mapped = opt.DecisionVariable.resolveClass(model, obj.jobclass);
50 if isempty(mapped), return; end
51
52 rt = model.initRoutingMatrix();
53 classes = model.getClasses();
54 for ci = 1:numel(classes)
55 c = classes{ci};
56 adj = conn;
57 if strcmp(c.getName(), mapped.getName())
58 adj(:, blocked) = 0.0;
59 end
60 for i = 1:n
61 outDegree = sum(adj(i, :));
62 if outDegree <= 0, continue; end
63 for j = 1:n
64 if adj(i, j) > 0
65 rt.set(c, c, nodes{i}, nodes{j}, adj(i, j) / outDegree);
66 end
67 end
68 end
69 end
70 model.link(rt);
71 end
72
73 function t = getVariableType(obj), t = 'class_mapping'; end
74 end
75end
Definition fjtag.m:157
Definition Station.m:245