Path Finding Functions

The functions on this page find paths between vertices within the graph. All functions in this module are called as methods on a TigerGraphConnection object.

shortestPath()

shortestPath(sourceVertices: Union[dict, tuple, list], targetVertices: Union[dict, tuple, list], maxLength: int = None, vertexFilters: Union[list, dict] = None, edgeFilters: Union[list, dict] = None, allShortestPaths: bool = False) → dict

Finds the shortest path (or all shortest paths) between the source and target vertex sets.

A vertex set is a set of dictionaries that each has three top-level keys: v_type, v_id, and attributes (also a dictionary).

Parameters:

  • sourceVertices: A vertex set (a list of vertices) or a list of (vertexType, vertexID) tuples; the source vertices of the shortest paths sought.

  • targetVertices: A vertex set (a list of vertices) or a list of (vertexType, vertexID) tuples; the target vertices of the shortest paths sought.

  • maxLength: The maximum length of a shortest path. Optional, default is 6.

  • vertexFilters: An optional list of (vertexType, condition) tuples or {"type": <str>, "condition": <str>} dictionaries.

  • edgeFilters: An optional list of (edgeType, condition) tuples or {"type": <str>, "condition": <str>} dictionaries.

  • allShortestPaths: If True, the endpoint will return all shortest paths between the source and target. Default is False, meaning that the endpoint will return only one path.

Returns:

The shortest path between the source and the target. The returned value is a subgraph: all vertices and edges that are part of the path(s); i.e. not a (list of individual) path(s).

Examples:

path = conn.shortestPath(("account", 10), ("person", 50), maxLength=3)

path = conn.shortestPath(("account", 10), ("person", 50), allShortestPaths=True,
vertexFilters=("transfer", "amount>950"), edgeFilters=("receive", "type=4"))

Endpoint:

allPaths()

allPaths(sourceVertices: Union[dict, tuple, list], targetVertices: Union[dict, tuple, list], maxLength: int, vertexFilters: Union[list, dict] = None, edgeFilters: Union[list, dict] = None) → dict

Find all possible paths up to a given maximum path length between the source and target vertex sets.

A vertex set is a dict that has three top-level keys: v_type, v_id, attributes (a dict).

Parameters:

  • sourceVertices: A vertex set (a list of vertices) or a list of (vertexType, vertexID) tuples; the source vertices of the shortest paths sought.

  • targetVertices: A vertex set (a list of vertices) or a list of (vertexType, vertexID) tuples; the target vertices of the shortest paths sought.

  • maxLength: The maximum length of the paths.

  • vertexFilters: An optional list of (vertexType, condition) tuples or {"type": <str>, "condition": <str>} dictionaries.

  • edgeFilters: An optional list of (edgeType, condition) tuples or {"type": <str>, "condition": <str>} dictionaries.

Returns:

All paths between a source vertex (or vertex set) and target vertex (or vertex set). The returned value is a subgraph: all vertices and edges that are part of the path(s); i.e. not a (list of individual) path(s).

Example:

path = conn.allPaths(("account", 10), ("person", 50), allShortestPaths=True,
vertexFilters=("transfer", "amount>950"), edgeFilters=("receive", "type=4"))

Endpoint: