LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
TaskReplication.m
1classdef TaskReplication < opt.DecisionVariable
2 % TaskReplication Optimize the replication (fan-out replicas) of an LQN
3 % Task (integer). Mirrors native-Python TaskReplication.
4
5 properties
6 task
7 minValue
8 maxValue
9 end
10
11 methods
12 function obj = TaskReplication(task, bounds, name)
13 taskName = opt.Layered.elemName(task);
14 if nargin < 3 || isempty(name)
15 name = [taskName '_replication'];
16 end
17 obj@opt.DecisionVariable(name);
18 obj.task = taskName;
19 obj.minValue = round(bounds(1));
20 obj.maxValue = round(bounds(2));
21 end
22
23 function b = getBounds(obj), b = opt.DecisionVariable.unitBounds(1); end
24
25 function v = decode(obj, x)
26 continuous = obj.minValue + x(1) * (obj.maxValue - obj.minValue);
27 v = min(max(round(continuous), obj.minValue), obj.maxValue);
28 end
29
30 function apply(obj, model, value)
31 task = opt.Layered.resolveTask(model, obj.task);
32 if ~isempty(task)
33 task.setReplication(round(value));
34 end
35 end
36
37 function t = getVariableType(obj), t = 'task_replication'; end
38
39 function layers = getLayer(obj, model)
40 layers = {obj.task};
41 proc = opt.Layered.taskProcessorName(model, obj.task);
42 if ~isempty(proc), layers{end+1} = proc; end
43 end
44
45 function v = currentValue(obj, model)
46 v = [];
47 task = opt.Layered.resolveTask(model, obj.task);
48 if isempty(task), return; end
49 r = task.getReplication();
50 if isnumeric(r) && isfinite(r), v = round(r); end
51 end
52 end
53end