LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getReward.m
1function [t, V, names, stateSpace] = getReward(self, rewardName)
2% GETREWARD Get reward value function over time from CTMC analysis
3%
4% [T, V, NAMES, STATESPACE] = GETREWARD(SELF) returns all rewards
5%
6% [T, V, NAMES, STATESPACE] = GETREWARD(SELF, REWARDNAME) returns the
7% specific reward with the given name
8%
9% OUTPUTS:
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]
16%
17% The value function V{r}(k,s) represents the cumulative reward accumulated
18% starting from state s after k time steps (uniformized).
19%
20% Example:
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
25%
26% Copyright (c) 2012-2026, Imperial College London
27% All rights reserved.
28
29if nargin < 2
30 rewardName = [];
31end
32
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;
40else
41 % Run the reward analyzer
42 [V, t, names, stateSpace] = self.runRewardAnalyzer();
43end
44
45% Filter to specific reward if requested
46if ~isempty(rewardName)
47 rewardName = char(rewardName);
48 idx = find(strcmp(names, rewardName));
49 if isempty(idx)
50 error('Reward "%s" not found. Available rewards: %s', ...
51 rewardName, strjoin(names, ', '));
52 end
53 V = V{idx};
54 names = names{idx};
55end
56
57end