1function [t, V, names, stateSpace] = getReward(self, rewardName)
2% GETREWARD Get reward value function over time from CTMC analysis
4% [T, V, NAMES, STATESPACE] = GETREWARD(SELF) returns all rewards
6% [T, V, NAMES, STATESPACE] = GETREWARD(SELF, REWARDNAME) returns the
7% specific reward with the given name
10% t - Time vector [1 x Tmax+1]
11% V - Value functions: cell array {nRewards x 1} where each
12% V{r}
is [Tmax+1 x nStates] matrix, or single matrix
if
13% rewardName
is specified
14% names - Cell array of reward names, or single name
string
15% stateSpace - State space matrix [nStates x nDims]
17% The value function V{r}(k,s) represents the cumulative reward accumulated
18% starting from state s after k time steps (uniformized).
21% model.setReward(
'qlen', @(state, sn) state(2));
22% solver = SolverCTMC(model);
23% [t, V, names] = solver.getReward();
24% plot(t, mean(V{1}, 2)); % Plot mean reward over time
26% Copyright (c) 2012-2026, Imperial College London
33% Check
if results are already cached
34if isfield(self.result,
'Reward') && ~isempty(self.result.Reward) && ...
35 isfield(self.result.Reward,
'V') && ~isempty(self.result.Reward.V)
36 V = self.result.Reward.V;
37 t = self.result.Reward.t;
38 names = self.result.Reward.names;
39 stateSpace = self.result.Reward.stateSpace;
41 % Run the reward analyzer
42 [V, t, names, stateSpace] = self.runRewardAnalyzer();
45% Filter to specific reward if requested
46if ~isempty(rewardName)
47 rewardName =
char(rewardName);
48 idx = find(strcmp(names, rewardName));
50 error('Reward "%s" not found. Available rewards: %s', ...
51 rewardName, strjoin(names, ', '));