LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ProcessorMultiplicity.m
1classdef ProcessorMultiplicity < opt.DecisionVariable
2 % ProcessorMultiplicity Optimize the multiplicity (core count) of an LQN
3 % Processor (integer). Mirrors native-Python ProcessorMultiplicity.
4
5 properties
6 processor
7 minValue
8 maxValue
9 end
10
11 methods
12 function obj = ProcessorMultiplicity(processor, bounds, name)
13 procName = opt.Layered.elemName(processor);
14 if nargin < 3 || isempty(name)
15 name = [procName '_multiplicity'];
16 end
17 obj@opt.DecisionVariable(name);
18 obj.processor = procName;
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 proc = opt.Layered.resolveProcessor(model, obj.processor);
32 if ~isempty(proc)
33 proc.multiplicity = round(value);
34 end
35 end
36
37 function t = getVariableType(obj), t = 'processor_multiplicity'; end
38
39 function layers = getLayer(obj, ~)
40 % A processor owns its own host layer, named after the processor.
41 layers = {obj.processor};
42 end
43
44 function v = currentValue(obj, model)
45 v = [];
46 proc = opt.Layered.resolveProcessor(model, obj.processor);
47 if isempty(proc), return; end
48 m = proc.multiplicity;
49 if isnumeric(m) && isfinite(m), v = round(m); end
50 end
51 end
52end