1classdef RewardDescriptor
2 % REWARDDESCRIPTOR Callable reward function carrying its own metadata
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
8 % fn = Reward.queueLength(queue1);
11 % keeps working unchanged,
while additionally exposing
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
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.
23 % See also: Reward, setReward, RewardState
25 % Copyright (c) 2012-2026, Imperial College London
26 % All rights reserved.
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
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.');
41 if ~isa(fn,
'function_handle')
42 line_error(mfilename, 'Reward descriptor must wrap a function handle.');
44 self.kind =
char(kind);
50 function varargout = subsref(self, s)
51 % SUBSREF Make
the descriptor callable as fn(state[, sn])
54 out = self.fn(s(1).subs{:});
56 [varargout{1:max(nargout,1)}] = subsref(out, s(2:end));
61 [varargout{1:max(nargout,1)}] = builtin(
'subsref', self, s);
65 function n = numArgumentsFromSubscript(self, s, indexingContext) %#ok<INUSD>
66 % NUMARGUMENTSFROMSUBSCRIPT A reward always produces exactly one value