1classdef ServerAllocation < opt.DecisionVariable
2 % ServerAllocation Optimize the number of servers at a station. Encodes an
3 % integer server count in [minServers, maxServers]. Mirrors native-Python
13 function obj = ServerAllocation(station, bounds, name)
14 if nargin < 3 || isempty(name)
15 name = [station.getName()
'_servers'];
17 obj@opt.DecisionVariable(name);
18 obj.station = station;
19 obj.minServers = round(bounds(1));
20 obj.maxServers = round(bounds(2));
23 function s = getStation(obj), s = obj.station; end
24 function b = getBounds(obj), b = opt.DecisionVariable.unitBounds(1); end
26 function v = decode(obj, x)
27 continuous = obj.minServers + x(1) * (obj.maxServers - obj.minServers);
28 v = min(max(round(continuous), obj.minServers), obj.maxServers);
31 function apply(obj, model, value)
32 nodes = model.getNodes();
33 for i = 1:numel(
nodes)
34 if strcmp(
nodes{i}.getName(), obj.station.getName())
35 nodes{i}.setNumberOfServers(value);
41 function t = getVariableType(obj), t =
'server_allocation'; end