LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MaximizePerformance.m
1classdef MaximizePerformance < opt.Objective
2 % MaximizePerformance Maximize weighted throughput + 1/RespT + 1/QLen,
3 % subject to an optional budget constraint. Returns negated performance
4 % (DE minimizes). Mirrors native-Python MaximizePerformance.
5
6 properties
7 throughputWeight = 1.0;
8 responseTimeWeight = 1.0;
9 queueLengthWeight = 0.0;
10 stations = []; % cell of station names, or [] = all
11 end
12
13 methods
14 function obj = MaximizePerformance(throughputWeight, responseTimeWeight, ...
15 queueLengthWeight, stations, budget, budgetTerms)
16 if nargin >= 1 && ~isempty(throughputWeight), obj.throughputWeight = throughputWeight; end
17 if nargin >= 2 && ~isempty(responseTimeWeight), obj.responseTimeWeight = responseTimeWeight; end
18 if nargin >= 3 && ~isempty(queueLengthWeight), obj.queueLengthWeight = queueLengthWeight; end
19 if nargin >= 4 && ~isempty(stations)
20 names = cell(1, numel(stations));
21 for i = 1:numel(stations)
22 names{i} = opt.Constraint.nameOf(stations{i});
23 end
24 obj.stations = names;
25 end
26 if nargin >= 5 && ~isempty(budget)
27 if nargin < 6, budgetTerms = []; end
28 obj.constraints = {opt.BudgetConstraint(budget, budgetTerms)};
29 end
30 end
31
32 function tf = isMinimization(~), tf = true; end
33
34 function v = evaluate(obj, result, ~)
35 performance = 0.0;
36 if isempty(obj.stations)
37 % unique station names from throughput keys 'station||class'
38 ks = keys(result.throughputs);
39 sts = {};
40 for i = 1:numel(ks)
41 parts = strsplit(ks{i}, '||');
42 sts{end+1} = parts{1}; %#ok<AGROW>
43 end
44 sts = unique(sts);
45 else
46 sts = obj.stations;
47 end
48 for i = 1:numel(sts)
49 station = sts{i};
50 if obj.throughputWeight > 0
51 performance = performance + obj.throughputWeight * result.getThroughput(station);
52 end
53 if obj.responseTimeWeight > 0
54 rt = result.getResponseTime(station);
55 if rt > 0 && isfinite(rt)
56 performance = performance + obj.responseTimeWeight * (1.0 / rt);
57 end
58 end
59 if obj.queueLengthWeight > 0
60 qlen = result.getQueueLength(station);
61 if qlen > 0
62 performance = performance + obj.queueLengthWeight * (1.0 / qlen);
63 end
64 end
65 end
66 v = -performance;
67 end
68 end
69end