All Paths (Single-Pair)
This algorithm finds and prints all paths between two input vertices. This is similar to the all-paths functionality in the standard GraphStudio viewer, except that it supports output of all vertices in all paths to a file or to the console. If you are using GraphStudio and only want a fast visual display of all paths, use the GraphStudio implementation instead of this algorithm.
There are directional and bidirectional versions of this algorithm.
Specifications
CREATE QUERY tg_all_path(VERTEX source_v, VERTEX target_v, INT maxDepth = 10,
BOOL print_accum = TRUE, STRING file_path = "")
CREATE QUERY tg_all_path_bidirection(VERTEX source_v, VERTEX target_v, SET<STRING> e_type, INT maxDepth = 3,
BOOL print_accum = TRUE, STRING file_path = "")
Parameters
Parameter | Description | Default value |
---|---|---|
|
Source vertex where the paths start. Provide the vertex ID and type as a tuple: |
N/A |
|
Target vertex where the paths end. Provide the vertex ID and type as a tuple: |
N/A |
|
Used for the bidirectional version of the algorithm. A set of strings referring to the edge types to use. |
(empty set of strings) |
|
The maximum length of the path returned. |
10 |
|
If |
True |
|
If not empty, write output to this file. |
(empty string) |
Example
Suppose we have a large network of consumers, products, and the contexts in which the products are used.
We want to find the contexts in which products P001
and P002
are both used.
This image was generated from GraphStudio using the Find Paths option in the Explore Graph window and limiting the maximum depth, or number of vertices in the path, to 3.
The paths can also be output in JSON format to the console or CSV format to a file using the all-paths algorithm.
RUN QUERY tg_all_path("P001", "P002", 3, TRUE, "/home/tigergraph/output.csv")