LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_set_routing_prob.m
1%{ @file sn_set_routing_prob.m
2 % @brief Sets a routing probability between two stateful node-class pairs
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Sets a routing probability
9 %
10 % @details
11 % Updates a single entry in the rt matrix.
12 %
13 % @par Syntax:
14 % @code
15 % sn = sn_set_routing_prob(sn, fromStateful, fromClass, toStateful, toClass, prob)
16 % sn = sn_set_routing_prob(sn, fromStateful, fromClass, toStateful, toClass, prob, autoRefresh)
17 % @endcode
18 %
19 % @par Parameters:
20 % <table>
21 % <tr><th>Name<th>Description
22 % <tr><td>sn<td>Network structure
23 % <tr><td>fromStateful<td>Source stateful node index (1-based)
24 % <tr><td>fromClass<td>Source class index (1-based)
25 % <tr><td>toStateful<td>Destination stateful node index (1-based)
26 % <tr><td>toClass<td>Destination class index (1-based)
27 % <tr><td>prob<td>Routing probability [0, 1]
28 % <tr><td>autoRefresh<td>If true, refresh visit ratios (default false)
29 % </table>
30 %
31 % @par Returns:
32 % <table>
33 % <tr><th>Name<th>Description
34 % <tr><td>sn<td>Modified network structure
35 % </table>
36%}
37function sn = sn_set_routing_prob(sn, fromStateful, fromClass, toStateful, toClass, prob, autoRefresh)
38
39if nargin < 7 || isempty(autoRefresh)
40 autoRefresh = false;
41end
42
43K = sn.nclasses;
44
45% Calculate indices in rt matrix (1-based)
46fromIdx = (fromStateful - 1) * K + fromClass;
47toIdx = (toStateful - 1) * K + toClass;
48
49% Update rt matrix
50sn.rt(fromIdx, toIdx) = prob;
51
52% Auto-refresh visit ratios if requested
53if autoRefresh
54 [~, ~, sn] = sn_refresh_visits(sn, sn.chains, sn.rt, sn.rtnodes);
55end
56
57end