1%{ @file sn_set_routing_prob.m
2 % @brief Sets a routing probability between two stateful node-
class pairs
4 % @author LINE Development Team
8 % @brief Sets a routing probability
11 % Updates a single entry in the rt matrix.
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)
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)
33 % <tr><th>Name<th>Description
34 % <tr><td>sn<td>Modified network structure
37function sn = sn_set_routing_prob(sn, fromStateful, fromClass, toStateful, toClass, prob, autoRefresh)
39if nargin < 7 || isempty(autoRefresh)
45% Calculate indices in rt matrix (1-based)
46fromIdx = (fromStateful - 1) * K + fromClass;
47toIdx = (toStateful - 1) * K + toClass;
50sn.rt(fromIdx, toIdx) = prob;
52% Auto-refresh visit ratios if requested
54 [~, ~, sn] = sn_refresh_visits(sn, sn.chains, sn.rt, sn.rtnodes);