Generate all simple paths in the graph G from source to target. A simple path is a path with no repeated nodes. Parameters ---------- G : NetworkX graph source : node Starting node for path target : nodes Single node or iterable of nodes at which to end path
(G, source, target_nodes, cutoff=None)
| 889 | |
| 890 | |
| 891 | def all_simple_paths(G, source, target_nodes, cutoff=None): |
| 892 | """Generate all simple paths in the graph G from source to target. |
| 893 | A simple path is a path with no repeated nodes. |
| 894 | Parameters |
| 895 | ---------- |
| 896 | G : NetworkX graph |
| 897 | source : node |
| 898 | Starting node for path |
| 899 | target : nodes |
| 900 | Single node or iterable of nodes at which to end path |
| 901 | cutoff : integer, optional |
| 902 | Depth to stop the search. Only paths of length <= cutoff are returned. |
| 903 | Returns |
| 904 | ------- |
| 905 | paths: list |
| 906 | A list that produces lists of simple paths. If there are no paths |
| 907 | between the source and target within the given cutoff the list |
| 908 | is empty. |
| 909 | Examples |
| 910 | -------- |
| 911 | >>> G = nx.complete_graph(4) |
| 912 | >>> print(nx.builtin.all_simple_paths(G, 0, 3)) |
| 913 | ... |
| 914 | [0, 1, 2, 3] |
| 915 | [0, 1, 3] |
| 916 | [0, 2, 1, 3] |
| 917 | [0, 2, 3] |
| 918 | [0, 3] |
| 919 | |
| 920 | """ |
| 921 | |
| 922 | paths = get_all_simple_paths(G, source, target_nodes, cutoff) |
| 923 | # delete path tail padding |
| 924 | for path in paths: |
| 925 | for i in range(len(path) - 1, -1, -1): |
| 926 | if path[i] == -1: |
| 927 | path.pop(i) |
| 928 | else: |
| 929 | break |
| 930 | return paths |
| 931 | |
| 932 | |
| 933 | def all_simple_edge_paths(G, source, target_nodes, cutoff=None): |
nothing calls this directly
no test coverage detected