apoc.algo.aStarConfig
Syntax |
|
||
Description |
Runs the A* search algorithm to find the optimal path between two |
||
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; |
|
|
|
{ weight = 'distance' :: STRING, default = Double.MAX_VALUE :: FLOAT, y = 'latitude' :: STRING, x = 'longitude' :: STRING, pointPropName :: STRING } |
|
Return arguments |
Name |
Type |
Description |
|
|
The path result. |
|
|
|
The weight of the given path. |
Example
Given this dataset:
CREATE (b:City {name:'Berlin', coords: point({latitude:52.52464,longitude:13.40514}), lat:52.52464,lon:13.40514})
CREATE (m:City {name:'München', coords: point({latitude:48.1374,longitude:11.5755}), lat:48.1374,lon:11.5755})
CREATE (f:City {name:'Frankfurt',coords: point({latitude:50.1167,longitude:8.68333}), lat:50.1167,lon:8.68333})
CREATE (h:City {name:'Hamburg', coords: point({latitude:53.554423,longitude:9.994583}), lat:53.554423,lon:9.994583})
CREATE (b)-[:DIRECT {dist:255.64*1000}]->(h)
CREATE (b)-[:DIRECT {dist:504.47*1000}]->(m)
CREATE (b)-[:DIRECT {dist:424.12*1000}]->(f)
CREATE (f)-[:DIRECT {dist:304.28*1000}]->(m)
CREATE (f)-[:DIRECT {dist:393.15*1000}]->(h)
It is possible to execute the following query (leveraging on lat
and lon
node properties, which are numbers,
on dist
relationship property and with default cost 100):
MATCH (from:City {name:'München'}), (to:City {name:'Hamburg'})
CALL apoc.algo.aStarConfig(from, to, 'DIRECT', {weight:'dist',y:'lat', x:'lon',default:100})
YIELD weight, path
RETURN weight, path
weight | path |
---|---|
697430.0 |
|
Or equivalently, with the same result, leveraging on coords
node property, which is a Point, with the same configurations.
Note that in case of a 3d-coordinate, the procedure will pick only the x and y or the longitude and latitude values.
MATCH (from:City {name:'München'}), (to:City {name:'Hamburg'})
CALL apoc.algo.aStarConfig(from, to, 'DIRECT', {pointPropName:'coords', weight:'dist', default:100})
YIELD weight, path
RETURN weight, path