LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
TaskMultiplicity.m
1classdef TaskMultiplicity < opt.DecisionVariable
2 % TaskMultiplicity Optimize the multiplicity (thread/instance count) of an
3 % LQN Task (integer). Mirrors native-Python TaskMultiplicity.
4
5 properties
6 task
7 minValue
8 maxValue
9 end
10
11 methods
12 function obj = TaskMultiplicity(task, bounds, name)
13 taskName = opt.Layered.elemName(task);
14 if nargin < 3 || isempty(name)
15 name = [taskName '_multiplicity'];
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 % Tasks store multiplicity as a public property (no setter);
34 % setting it directly mirrors how the LQN builder assigns it.
35 task.multiplicity = round(value);
36 end
37 end
38
39 function t = getVariableType(obj), t = 'task_multiplicity'; end
40
41 function layers = getLayer(obj, model)
42 layers = {obj.task};
43 proc = opt.Layered.taskProcessorName(model, obj.task);
44 if ~isempty(proc), layers{end+1} = proc; end
45 end
46
47 function v = currentValue(obj, model)
48 v = [];
49 task = opt.Layered.resolveTask(model, obj.task);
50 if isempty(task), return; end
51 m = task.multiplicity;
52 if isnumeric(m) && isfinite(m), v = round(m); end
53 end
54 end
55end