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.
11 targets % cell array of Node
15 function obj = RoutingProbabilities(
jobclass, source, targets, name)
16 if nargin < 4 || isempty(name)
17 name = [
jobclass.getName()
'_routing_from_' source.getName()];
19 obj@opt.DecisionVariable(name);
22 obj.targets = targets;
23 obj.dimension = max(1, numel(targets) - 1);
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
31 function probs = decode(obj, x)
32 n = numel(obj.targets);
39 probs(i) = remaining * x(i);
40 remaining = remaining - probs(i);
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});
57 src.setProbRouting(cls, target, value(i));
62 function t = getVariableType(obj), t = 'routing
'; end