LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_refresh_process_fields.m
1%{ @file sn_refresh_process_fields.m
2 % @brief Refreshes process fields based on rate and SCV values
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Refreshes process fields for a station-class pair
9 %
10 % @details
11 % Updates mu, phi, proc, pie, phases based on current rate and SCV values.
12 % - SCV = 1.0: Exponential (1 phase)
13 % - SCV < 1.0: Erlang approximation
14 % - SCV > 1.0: Hyperexponential(2) approximation
15 %
16 % @par Syntax:
17 % @code
18 % sn = sn_refresh_process_fields(sn, stationIdx, classIdx)
19 % @endcode
20 %
21 % @par Parameters:
22 % <table>
23 % <tr><th>Name<th>Description
24 % <tr><td>sn<td>Network structure
25 % <tr><td>stationIdx<td>Station index (1-based)
26 % <tr><td>classIdx<td>Class index (1-based)
27 % </table>
28 %
29 % @par Returns:
30 % <table>
31 % <tr><th>Name<th>Description
32 % <tr><td>sn<td>Modified network structure
33 % </table>
34%}
35function sn = sn_refresh_process_fields(sn, stationIdx, classIdx)
36
37rate = sn.rates(stationIdx, classIdx);
38scv = sn.scv(stationIdx, classIdx);
39
40% Skip if rate is invalid
41if isnan(rate) || rate <= 0 || isinf(rate)
42 return;
43end
44
45mean = 1.0 / rate;
46
47% Determine process type and create MAP based on SCV
48if isnan(scv) || abs(scv - 1.0) < 1e-10
49 % Exponential
50 MAP = map_exponential(mean);
51 nPhases = 1;
52 procType = ProcessType.EXP;
53elseif scv < 1.0
54 % Erlang: k = ceil(1/scv)
55 k = max(1, ceil(1.0 / scv));
56 MAP = map_erlang(mean, k);
57 nPhases = k;
58 procType = ProcessType.ERLANG;
59else
60 % Hyperexponential (scv > 1)
61 MAP = map_hyperexp(mean, scv);
62 if ~isempty(MAP)
63 nPhases = 2;
64 procType = ProcessType.HYPEREXP;
65 else
66 % Fallback to exponential
67 MAP = map_exponential(mean);
68 nPhases = 1;
69 procType = ProcessType.EXP;
70 end
71end
72
73% Update process fields
74D0 = MAP{1};
75D1 = MAP{2};
76
77% Update proc
78sn.proc{stationIdx, classIdx} = MAP;
79
80% Update procid
81sn.procid(stationIdx, classIdx) = procType;
82
83% Update phases
84sn.phases(stationIdx, classIdx) = nPhases;
85
86% Update phasessz
87sn.phasessz(stationIdx, classIdx) = max(nPhases, 1);
88
89% Recompute phaseshift for this station
90cumSum = 0;
91sn.phaseshift(stationIdx, 1) = 0;
92for c = 1:sn.nclasses
93 cumSum = cumSum + sn.phasessz(stationIdx, c);
94 if c + 1 <= size(sn.phaseshift, 2)
95 sn.phaseshift(stationIdx, c + 1) = cumSum;
96 end
97end
98
99% Update mu (rates from -diag(D0))
100muVec = -diag(D0);
101sn.mu{stationIdx, classIdx} = muVec;
102
103% Update phi (completion probabilities)
104phiVec = zeros(nPhases, 1);
105for i = 1:nPhases
106 d1RowSum = sum(D1(i, :));
107 d0Diag = -D0(i, i);
108 if d0Diag ~= 0
109 phiVec(i) = d1RowSum / d0Diag;
110 end
111end
112sn.phi{stationIdx, classIdx} = phiVec;
113
114% Update pie (initial phase distribution)
115sn.pie{stationIdx, classIdx} = map_pie(MAP);
116
117end