LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
RewardDescriptor.m
1classdef RewardDescriptor
2 % REWARDDESCRIPTOR Callable reward function carrying its own metadata
3 %
4 % A RewardDescriptor wraps a reward function handle together with a
5 % structural description of what the reward measures. It is CALLABLE
6 % exactly like the bare function handle it replaces, so that
7 %
8 % fn = Reward.queueLength(queue1);
9 % value = fn(state);
10 %
11 % keeps working unchanged, while additionally exposing
12 %
13 % fn.kind - 'QLen' | 'Util' | 'Blocking' | 'Custom'
14 % fn.node - Node object the reward refers to ([] if none)
15 % fn.jobclass - JobClass object the reward refers to ([] if none)
16 % fn.fn - the underlying function handle
17 %
18 % The metadata is what allows setReward/linemodel_save to serialize the
19 % reward declaratively. A descriptor of kind 'Custom' wraps an arbitrary
20 % user function and is deliberately NOT serializable: the writer warns and
21 % omits it rather than emitting a reward it cannot reproduce.
22 %
23 % See also: Reward, setReward, RewardState
24 %
25 % Copyright (c) 2012-2026, Imperial College London
26 % All rights reserved.
27
28 properties
29 kind; % char: 'QLen' | 'Util' | 'Blocking' | 'Custom'
30 node; % Node object, or [] when the reward is not node-scoped
31 jobclass; % JobClass object, or [] when the reward is not class-scoped
32 fn; % function_handle actually evaluated
33 end
34
35 methods
36 function self = RewardDescriptor(kind, node, jobclass, fn)
37 % SELF = REWARDDESCRIPTOR(KIND, NODE, JOBCLASS, FN)
38 if ~ischar(kind) && ~isstring(kind)
39 line_error(mfilename, 'Reward kind must be a string.');
40 end
41 if ~isa(fn, 'function_handle')
42 line_error(mfilename, 'Reward descriptor must wrap a function handle.');
43 end
44 self.kind = char(kind);
45 self.node = node;
46 self.jobclass = jobclass;
47 self.fn = fn;
48 end
49
50 function varargout = subsref(self, s)
51 % SUBSREF Make the descriptor callable as fn(state[, sn])
52 switch s(1).type
53 case '()'
54 out = self.fn(s(1).subs{:});
55 if numel(s) > 1
56 [varargout{1:max(nargout,1)}] = subsref(out, s(2:end));
57 else
58 varargout{1} = out;
59 end
60 otherwise
61 [varargout{1:max(nargout,1)}] = builtin('subsref', self, s);
62 end
63 end
64
65 function n = numArgumentsFromSubscript(self, s, indexingContext) %#ok<INUSD>
66 % NUMARGUMENTSFROMSUBSCRIPT A reward always produces exactly one value
67 n = 1;
68 end
69 end
70end
Definition Station.m:245