LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
RoutingProbabilities.m
1classdef RoutingProbabilities < opt.DecisionVariable
2 % RoutingProbabilities Optimize routing of a job class from a source node
3 % to target nodes. Stick-breaking encoding (dim = targets-1). On apply,
4 % default routing is rebuilt from the connection matrix for every class,
5 % then the overridden (class, source) row is set to the decoded
6 % probabilities. Mirrors native-Python RoutingProbabilities.
7
8 properties
10 source
11 targets % cell array of Node
12 end
13
14 methods
15 function obj = RoutingProbabilities(jobclass, source, targets, name)
16 if nargin < 4 || isempty(name)
17 name = [jobclass.getName() '_routing_from_' source.getName()];
18 end
19 obj@opt.DecisionVariable(name);
20 obj.jobclass = jobclass;
21 obj.source = source;
22 obj.targets = targets;
23 obj.dimension = max(1, numel(targets) - 1);
24 end
25
26 function c = getJobClass(obj), c = obj.jobclass; end
27 function s = getSource(obj), s = obj.source; end
28 function t = getTargets(obj), t = obj.targets; end
29 function b = getBounds(obj), b = opt.DecisionVariable.unitBounds(obj.dimension); end
30
31 function probs = decode(obj, x)
32 n = numel(obj.targets);
33 if n == 1
34 probs = 1.0; return;
35 end
36 probs = zeros(1, n);
37 remaining = 1.0;
38 for i = 1:(n-1)
39 probs(i) = remaining * x(i);
40 remaining = remaining - probs(i);
41 end
42 probs(n) = remaining;
43 end
44
45 function apply(obj, model, value)
46 % Override only the source node's outgoing routing for this class,
47 % via setProbRouting, leaving all other routes intact. This is the
48 % MATLAB idiom that works whether the model was built with link()
49 % or addLink() (model.link() is rejected after addLink()).
50 cls = opt.DecisionVariable.resolveClass(model, obj.jobclass);
51 if isempty(cls), return; end
52 src = opt.DecisionVariable.resolveNode(model, obj.source);
53 if isempty(src), return; end
54 for i = 1:numel(obj.targets)
55 target = opt.DecisionVariable.resolveNode(model, obj.targets{i});
56 if ~isempty(target)
57 src.setProbRouting(cls, target, value(i));
58 end
59 end
60 end
61
62 function t = getVariableType(obj), t = 'routing'; end
63 end
64end
Definition fjtag.m:157
Definition Station.m:245