擅长:python、mysql、java
<p>我找到了这个Python模块<a href="https://networkx.github.io/" rel="nofollow">Networkx</a>,它对我帮助很大。<br/>
<a href="https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html" rel="nofollow">This</a>(networkx.最短路径)特别是我使用的函数。在</p>
<p>贴在对我有用的溶液下面。在</p>
<pre><code>import networkx as nx
G = nx.DiGraph()
G.add_nodes_from(["Start", "a", "b", "c", "End"])
G.add_edges_from([("Start", "a"), ("Start", "c"), ("a", "b"), ("b", "a"), ("c", "End")])
total_num_nodes = G.number_of_nodes()
if len(nx.shortest_path(G, source="Start")) < total_num_nodes:
print "\nThis FSM has inaccessible states"
else:
print "\nAll nodes reachable from 'Start'"
H = G.reverse()
if len(nx.shortest_path(H, source="End")) < total_num_nodes:
print "\nThis FSM has dead-end states"
else:
print "\nAll nodes have a path to reach the 'End' state"
</code></pre>