LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_get_residt_from_respt.m
1%{ @file sn_get_residt_from_respt.m
2 % @brief Computes residence times from response times
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes residence times from response times
9 %
10 % @details
11 % This function converts response times to residence times by accounting
12 % for visit ratios at each station.
13 %
14 % @par Syntax:
15 % @code
16 % WN = sn_get_residt_from_respt(sn, RN, WH)
17 % @endcode
18 %
19 % @par Parameters:
20 % <table>
21 % <tr><th>Name<th>Description
22 % <tr><td>sn<td>Network structure
23 % <tr><td>RN<td>Average response times
24 % <tr><td>WH<td>Residence time handles
25 % </table>
26 %
27 % @par Returns:
28 % <table>
29 % <tr><th>Name<th>Description
30 % <tr><td>WN<td>Average residence times
31 % </table>
32%}
33function WN=sn_get_residt_from_respt(sn, RN, WH)
34
35M = sn.nstations;
36K = sn.nclasses;
37WN = zeros(M, K);
38
39% sn.visits is cell array of stateful-indexed matrices (nstateful x nclasses)
40% We need to convert to station-indexed matrix (M x K) using statefulToStation
41Vstateful = cellsum(sn.visits);
42V = zeros(M, K);
43for sf = 1:sn.nstateful
44 stationIdx = sn.statefulToStation(sf);
45 if ~isnan(stationIdx) && stationIdx >= 1 && stationIdx <= M
46 V(stationIdx, :) = V(stationIdx, :) + Vstateful(sf, :);
47 end
48end
49
50for ist = 1:M
51 for k = 1:K
52 if isempty(WH) || WH{ist,k}.disabled
53 WN(ist,k) = NaN;
54 elseif ~isempty(RN) && RN(ist,k) > 0
55 if RN(ist,k) < GlobalConstants.FineTol
56 WN(ist,k) = RN(ist,k);
57 else
58 c = find(sn.chains(:, k));
59 refclass = sn.refclass(c);
60 if refclass > 0
61 WN(ist,k) = RN(ist,k) * V(ist,k) / sum(V(sn.refstat(k), refclass));
62 else
63 WN(ist,k) = RN(ist,k) * V(ist,k) / sum(V(sn.refstat(k), sn.inchain{c}));
64 end
65 end
66 end
67 end
68end
69WN(isnan(WN)) = 0;
70WN(WN < 10 * GlobalConstants.FineTol) = 0;
71WN(WN < GlobalConstants.FineTol) = 0;
72end