apoc.algo.aStarConfig
Procedure APOC Core
apoc.algo.aStar(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', {weight:'dist',default:10,x:'lon',y:'lat'}) YIELD path, weight - run A* with relationship property name as cost function
Signature
apoc.algo.aStarConfig(startNode :: NODE?, endNode :: NODE?, relationshipTypesAndDirections :: STRING?, config :: MAP?) :: (path :: PATH?, weight :: FLOAT?)
Input parameters
Name | Type | Default |
---|---|---|
startNode |
NODE? |
null |
endNode |
NODE? |
null |
relationshipTypesAndDirections |
STRING? |
null |
config |
MAP? |
null |
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (b:City {name:'Berlin',lat:52.52464,lon:13.40514})
CREATE (m:City {name:'München',lat:48.1374,lon:11.5755})
CREATE (f:City {name:'Frankfurt',lat:50.1167,lon:8.68333})
CREATE (h:City {name:'Hamburg',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);
We can find the shortest path from München to Hamburg, by running the following query:
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 path, weight
RETURN path, weight;
path | weight |
---|---|
(:City {name: "München", lon: 11.5755, lat: 48.1374})←[:DIRECT {dist: 304280.0}]-(:City {name: "Frankfurt", lon: 8.68333, lat: 50.1167})-[:DIRECT {dist: 393150.0}]→(:City {name: "Hamburg", lon: 9.994583, lat: 53.554423}) |
697430.0 |
Was this page helpful?