apoc.algo.allSimplePathsProcedure
|
This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime. For more information, see the Cypher Manual → Parallel runtime. |
Syntax |
|
||
Description |
Runs a search algorithm to find all of the simple paths between the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The node to start the search from. |
|
|
|
The node to end the search on. |
|
|
|
The relationship types to restrict the algorithm to. Relationship types are represented using APOC’s rel-direction-pattern syntax; |
|
|
|
The max depth (in terms of nodes) the algorithm will explore. |
|
Return arguments |
Name |
Type |
Description |
|
|
The path result. |
|
Example
Given this dataset:
CREATE (a:Place {name: 'A'}),
(b:Place {name: 'B'}),
(c:Place {name: 'C'}),
(d:Place {name: 'D'}),
(a)-[:ROAD]->(b),
(b)-[:ROAD]->(c),
(c)-[:ROAD]->(d),
(b)-[:ROAD]->(d),
(a)-[:ROAD]->(c),
(a)-[:ROAD]->(d)
The following query returns all simple paths from A to D up to a maximum depth of 2 relationships:
MATCH (start:Place {name: 'A'}), (end:Place {name: 'D'})
CALL apoc.algo.allSimplePaths(start, end, 'ROAD>', 2)
YIELD path
RETURN [n IN nodes(path) | n.name] AS route, length(path) AS hops
ORDER BY hops
| route | hops |
|---|---|
["A", "D"] |
1 |
["A", "B", "D"] |
2 |
["A", "C", "D"] |
2 |
The route ["A", "B", "C", "D"] is left out as requires 3 hops.