Hello Community!
Can anyone help me explain this? I'm working on a navigation project and returning routes using both Dijkstra and A*. Both calculations use practically identical queries - except for the addition of the latitude and longitude parameters for A*. Something strange seems to be happening with the A* calculation though, because the path being returned is definitely not the shortest
The data has been taken from OpenStreetMap and added/appended for routing.
This is the Dijkstra result:
This is the A* result with the same start source and target:
And here's the call being used :
MATCH(x:PointOfInterest)-[:TAGS]-(t:OSMTags)
WHERE t.name contains('<Name-of-destination>')
MATCH (p:ParkingSpaceNode)
WITH x,id(p) as pId, distance(x.location,p.location) as d
ORDER BY d ASC LIMIT 1
CALL gds.shortestPath.astar.stream({
sourceNode:pId,
targetNode:id(x),
nodeProjection: '*',
nodeProperties:['lat','lon'],
relationshipProjection:{
all:{
type:'ROUTE',
properties:'distance',
orientation:'UNDIRECTED'
}
},
longitudeProperty: 'lon',
latitudeProperty: 'lat',
relationshipWeightProperty:'distance'
}) YIELD nodeIds, totalCosts //include totalCosts for analysis
WITH [nodeId IN nodeIds | gds.util.asNode(nodeId).location] as coords
RETURN coords
A short explanation:
- I select a destination and derived the closest non-occupied parking space based on the "line-of-site" distance. (WITH... distance() ... LIMIT 1). This works fine.
- Calculate the path using A* or Dijkstra.
- The returned coordinates are then packaged in a GeoJSON and sent to a MapBox display.
The path calculation is undirected, and all relations (pathways) are "two-way"...
The example shown in the pictures calculate a 70m path with Dijkstra and 413m for A*
Is anyone working with A* at the moment that could help explain what might be happening in the middle to divert the path so far out of the way?
Any ideas would be greatly appreciated!
Mike