LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ServerAllocation.m
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
4 % ServerAllocation.
5
6 properties
7 station
8 minServers
9 maxServers
10 end
11
12 methods
13 function obj = ServerAllocation(station, bounds, name)
14 if nargin < 3 || isempty(name)
15 name = [station.getName() '_servers'];
16 end
17 obj@opt.DecisionVariable(name);
18 obj.station = station;
19 obj.minServers = round(bounds(1));
20 obj.maxServers = round(bounds(2));
21 end
22
23 function s = getStation(obj), s = obj.station; end
24 function b = getBounds(obj), b = opt.DecisionVariable.unitBounds(1); end
25
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);
29 end
30
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);
36 return;
37 end
38 end
39 end
40
41 function t = getVariableType(obj), t = 'server_allocation'; end
42 end
43end
Definition fjtag.m:161