LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_set_service_batch.m
1%{ @file sn_set_service_batch.m
2 % @brief Sets service rates for multiple station-class pairs
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Sets service rates for multiple station-class pairs
9 %
10 % @details
11 % Batch update of service rates. NaN values are skipped (not updated).
12 % More efficient than calling sn_set_service multiple times.
13 %
14 % @par Syntax:
15 % @code
16 % sn = sn_set_service_batch(sn, rates)
17 % sn = sn_set_service_batch(sn, rates, scvs)
18 % sn = sn_set_service_batch(sn, rates, scvs, autoRefresh)
19 % @endcode
20 %
21 % @par Parameters:
22 % <table>
23 % <tr><th>Name<th>Description
24 % <tr><td>sn<td>Network structure
25 % <tr><td>rates<td>Matrix of new rates (nstations x nclasses), NaN = skip
26 % <tr><td>scvs<td>Matrix of new SCVs (optional)
27 % <tr><td>autoRefresh<td>If true, refresh process fields (default false)
28 % </table>
29 %
30 % @par Returns:
31 % <table>
32 % <tr><th>Name<th>Description
33 % <tr><td>sn<td>Modified network structure
34 % </table>
35%}
36function sn = sn_set_service_batch(sn, rates, scvs, autoRefresh)
37
38if nargin < 3
39 scvs = [];
40end
41
42if nargin < 4 || isempty(autoRefresh)
43 autoRefresh = false;
44end
45
46M = sn.nstations;
47K = sn.nclasses;
48
49% Track updated pairs for auto-refresh
50updatedPairs = [];
51
52% Update rates
53for i = 1:M
54 for j = 1:K
55 if ~isnan(rates(i, j))
56 sn.rates(i, j) = rates(i, j);
57 updatedPairs = [updatedPairs; i, j]; %#ok<AGROW>
58 end
59 end
60end
61
62% Update SCVs if provided
63if ~isempty(scvs)
64 for i = 1:M
65 for j = 1:K
66 if ~isnan(scvs(i, j))
67 sn.scv(i, j) = scvs(i, j);
68 end
69 end
70 end
71end
72
73% Auto-refresh if requested
74if autoRefresh
75 for idx = 1:size(updatedPairs, 1)
76 sn = sn_refresh_process_fields(sn, updatedPairs(idx, 1), updatedPairs(idx, 2));
77 end
78end
79
80end