[[NetworkX]]のall_simple_pathsメソッドを使用する。 [all_simple_paths — NetworkX 2.7 documentation](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.simple_paths.all_simple_paths.html) - 経路の始点と終点を指定する必要がある。 - 複数のルートノードと複数のリーフノード間のそれぞれの組み合わせの経路を取得する場合は、次のように、in_degreeとout_degreeメソッドを使う。 > Iterate over each path from the root nodes to the leaf nodes in a directed acyclic graph passing all leaves together to avoid unnecessary compute: > 有向無サイクルグラフのルートノードからリーフノードへの各パスを、すべてのリーフを一緒に通過させることで不要な計算を回避する。 ```python >>> G = nx.DiGraph([(0, 1), (2, 1), (1, 3), (1, 4)]) >>> roots = (v for v, d in G.in_degree() if d == 0) >>> leaves = [v for v, d in G.out_degree() if d == 0] >>> all_paths = [] >>> for root in roots: >>> paths = nx.all_simple_paths(G, root, leaves) >>> all_paths.extend(paths) >>> all_paths [[0, 1, 3], [0, 1, 4], [2, 1, 3], [2, 1, 4]] ```