1classdef TaskReplication < opt.DecisionVariable
2 % TaskReplication Optimize the replication (fan-out replicas) of an LQN
3 % Task (integer). Mirrors native-Python TaskReplication.
12 function obj = TaskReplication(task, bounds, name)
13 taskName = opt.Layered.elemName(task);
14 if nargin < 3 || isempty(name)
15 name = [taskName
'_replication'];
17 obj@opt.DecisionVariable(name);
19 obj.minValue = round(bounds(1));
20 obj.maxValue = round(bounds(2));
23 function b = getBounds(obj), b = opt.DecisionVariable.unitBounds(1); end
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);
30 function apply(obj, model, value)
31 task = opt.Layered.resolveTask(model, obj.task);
33 task.setReplication(round(value));
37 function t = getVariableType(obj), t =
'task_replication'; end
39 function layers = getLayer(obj, model)
41 proc = opt.Layered.taskProcessorName(model, obj.task);
42 if ~isempty(proc), layers{end+1} = proc; end
45 function v = currentValue(obj, model)
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