I have a problem to tackle: find all reachable nodes path to which will be under certain weight. Already solved problem from programming language perspective of view, but now I want to do it the right way through call to neo4j. Consider following node connections:
1-(2)--3
| \ |
(3)(9) (1)
| \ |
2-(9)--4-(1)-5
In case formatting is not clear:
1->2 distance:3
1->3 distance:2
1->4 distance:9
3->4 distance:1
2->4 distance:9
4->5 distance:1
Assumption is, for starting point 1 and overall weight=5 we could reach every single node: 1->2 (3) 1->3->4->5 (4)
I know it could also be done "manually" by searching for shortest paths to each node in db and finding all, to which weight is less than 5, however, I think bfs /dfs are more suitable for this since for large dataset manual solution would be really slow for any query. So I for bfs/dfs I found following solution:
Match(n:Place {name:"one"})
call algo.bfs.stream("Place", "Connection", "BOTH", id(n),
{maxCost:5, weightProperty:'distance'})
yield nodeIds
unwind nodeIds as nodeId
return algo.asNode(nodeId)
however, result is only nodes 1, 2 and 3 (directly accessible) and I can't quite get, why it is so. if I remove connections 1->4 and 2->4, result is as expected. Why is algo.bfs/dfs not working for such case? If I search with maxCost 11, result is as expected - all nodes.
I'm with Neo4j, we had some from the analytics team take a look. We've confirmed this is a bug affecting both dfs and bfs implementations, we'll have a fix out with the next algos patch release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With