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_find_all_path(VERTEX source_v, VERTEX target_v, INT maxDepth,
BOOL print_accum = TRUE, STRING file_path = "")
CREATE QUERY tg_find_all_path_bidirection(VERTEX source_v, VERTEX target_v, INT maxDepth,
BOOL print_accum = TRUE, STRING file_path = "")
Parameters
Parameter | Data type | Description |
---|---|---|
|
|
Source vertex where the paths start. |
|
|
Target vertex where the paths end. |
|
|
The maximum length of the path returned. |
|
|
If |
|
|
If not empty, write output to this file. |
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_find_all_path("P001", "P002", 3, TRUE, "/home/tigergraph/output.csv")