In Neo4j, I have a network of connected nodes, and the connections all have a weight associated to them.
I want to be able to specify a starting node and a max distance (by distance I mean sum of weights on the edges the path goes through), and get in return all the nodes that are reachable within that distance.
I do not want to compute the minimum distance for all the nodes in my graph, so I was wondering if there was an algorithm that can "explore" the graph from a starting node, and stop once it hits a threshold.
I am not necessarily looking for a solution, but I could use some links to relevant documentation
0
votes
1 Answers
0
votes
I'm using the following, which does the trick (bracketed fields are formatted with some input).
CALL apoc.path.spanningTree(n, {{relationshipFilter:'{relationship_filter}', labelFilter:'{label_filter}', minLevel:{min_level}, maxLevel:{max_level}}}) YIELD path
WITH last(nodes(path)) as node, reduce(weight = 0, rel IN relationships(path) | weight+rel.weight) as depth
WHERE depth<{weighted_depth_limit}
WITH depth, collect(node) as nodes_at_depth
ORDER BY depth ASC
RETURN nodes_at_depth, depth