1classdef ProcessorMultiplicity < opt.DecisionVariable
2 % ProcessorMultiplicity Optimize the multiplicity (core count) of an LQN
3 % Processor (integer). Mirrors native-Python ProcessorMultiplicity.
12 function obj = ProcessorMultiplicity(processor, bounds, name)
13 procName = opt.Layered.elemName(processor);
14 if nargin < 3 || isempty(name)
15 name = [procName
'_multiplicity'];
17 obj@opt.DecisionVariable(name);
18 obj.processor = procName;
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 proc = opt.Layered.resolveProcessor(model, obj.processor);
33 proc.multiplicity = round(value);
37 function t = getVariableType(obj), t =
'processor_multiplicity'; end
39 function layers = getLayer(obj, ~)
40 % A processor owns its own host layer, named after the processor.
41 layers = {obj.processor};
44 function v = currentValue(obj, model)
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