MCPcopy Create free account
hub / github.com/alibaba/GraphScope / all_simple_edge_paths

Function all_simple_edge_paths

python/graphscope/nx/algorithms/builtin.py:933–973  ·  view source on GitHub ↗

Generate lists of edges for all simple paths in 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

(G, source, target_nodes, cutoff=None)

Source from the content-addressed store, hash-verified

931
932
933def all_simple_edge_paths(G, source, target_nodes, cutoff=None):
934 """Generate lists of edges for all simple paths in G from source to target.
935 A simple path is a path with no repeated nodes.
936 Parameters
937 ----------
938 G : NetworkX graph
939 source : node
940 Starting node for path
941 target : nodes
942 Single node or iterable of nodes at which to end path
943 cutoff : integer, optional
944 Depth to stop the search. Only paths of length <= cutoff are returned.
945 Returns
946 -------
947 paths: list
948 A list that produces lists of simple edge paths. If there are no paths
949 between the source and target within the given cutoff the list
950 is empty.
951 Examples
952 --------
953 Print the simple path edges of a Graph::
954 >>> g = nx.Graph([(1, 2), (2, 4), (1, 3), (3, 4)])
955 >>> print(nx.builtin.all_simple_paths(G, 1, 4))
956 [(1, 2), (2, 4)]
957 [(1, 3), (3, 4)]
958
959 """
960
961 paths = get_all_simple_paths(G, source, target_nodes, cutoff)
962 for path in paths:
963 a = ""
964 b = ""
965 for i in range(len(path) - 1, -1, -1):
966 if path[i] == -1:
967 a = path.pop(i)
968 else:
969 b = path.pop(i)
970 if a != -1 and a != "":
971 path.insert(i, (b, a))
972 a = b
973 return paths
974
975
976def betweenness_centrality(

Callers

nothing calls this directly

Calls 3

get_all_simple_pathsFunction · 0.85
insertMethod · 0.65
popMethod · 0.45

Tested by

no test coverage detected