It is troublesome to write each time, so create it in the form of an adjacency list
import networkx as nx
g = nx.read_adjlist('/path/to/adjacencylist', create_using=nx.DiGraph())
print('nodes: ' + ', '.join(g.nodes()))
print
Display all nodes in the graph by adding a statement.
If you add weights etc., you need them separately, but for the sake of simplicity, we will not consider weights here.
nx.shortest_path(g, source="hoge", target="fuga")
The return value will be a list containing nodes
for path in nx.all_simple_paths(g, source='hoge", target="fuga"):
print(path)
It also displays the detour route.
Recommended Posts