apoc.algo.dijkstraProcedure
Syntax |
|
||
Description |
Runs Dijkstra’s algorithm using 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 name of the property to use as the weight. |
|
|
|
The |
|
|
|
The number of wanted paths to return. The default is: |
|
Return arguments |
Name |
Type |
Description |
|
|
The path result. |
|
|
|
The weight of the given path. |
|
Example
Given this dataset:
CREATE (london:Station {name: 'London'}),
(birmingham:Station {name: 'Birmingham'}),
(manchester:Station {name: 'Manchester'}),
(london)-[:TRAIN {time: 82}]->(birmingham),
(birmingham)-[:TRAIN {time: 35}]->(manchester),
(london)-[:TRAIN {time: 130}]->(manchester)
The following query finds the fastest route from London to Manchester, using the time property as the cost:
MATCH (start:Station {name: 'London'}), (end:Station {name: 'Manchester'})
CALL apoc.algo.dijkstra(start, end, 'TRAIN>', 'time')
YIELD path, weight
RETURN [n IN nodes(path) | n.name] AS route, weight
| route | weight |
|---|---|
["London", "Birmingham", "Manchester"] |
117.0 |