LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_is_state_valid.m
1%{ @file sn_is_state_valid.m
2 % @brief Validates a network state
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Validates a network state
9 %
10 % @details
11 % Checks if a given state vector represents a valid state for the network.
12 %
13 % @par Syntax:
14 % @code
15 % bool = sn_is_state_valid(sn)
16 % @endcode
17 %
18 % @par Parameters:
19 % <table>
20 % <tr><th>Name<th>Description
21 % <tr><td>sn<td>Network structure
22 % </table>
23 %
24 % @par Returns:
25 % <table>
26 % <tr><th>Name<th>Description
27 % <tr><td>bool<td>True if the state is valid for this network
28 % </table>
29%}
30function [isvalid] = sn_is_state_valid(sn)
31% [ISVALID] = ISSTATEVALID()
32nir = [];
33sir = [];
34for ist=1:sn.nstations
35 isf = sn.stationToStateful(ist);
36 if size(sn.state{isf},1)>1
37 line_warning(mfilename,sprintf('isStateValid will ignore some states of station %d, define a unique initial state to address this problem.\n',ist));
38 sn.state{isf} = sn.state{isf}(1,:);
39 end
40 [~, nir(ist,:), sir(ist,:), ~] = State.toMarginal(sn, sn.stationToNode(ist), sn.state{isf});
41end
42isvalid = State.isValid(sn, nir, sir);
43end