neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            
https://neo4j.com/labs/apoc
Apache License 2.0
1.71k stars 493 forks source link

I have some issues about dijikstra #988

Closed Heermosi closed 5 years ago

Heermosi commented 6 years ago

***1. When I tried to calculate the shortest path, it gives result of non-directional shortest path, while I want a directional one. I wonder how to set the parameter so that I may get a desired result?

  1. I think it was necessary to return "all shorest paths" with "a limited number", currently I can make it work around by grouping the results.

The first is most important, I think it might be something implemented but not written in document. Thank you for your reading

with some code: MATCH (c:Character), (d:Character) where c.nickname = 'xxxxx' and d.nickname = 'yyyyy' CALL apoc.algo.dijkstra(c, d, 'SHARE', 'iweight', 0, 99) YIELD path, weight With weight, collect(path) as ps order by weight LIMIT 1 UNWIND ps as p return nodes(p), relationships(p) We want this [:SHARE] calculation be directional

sarmbruster commented 6 years ago

1) Have you tried to use a > or < in the relationship specification, e.g. call apoc.algo.dijkstra(startNode, endNode, 'DELAYS>', 'time') yield path, weight ? This should only consider paths like (startNode)-[:DELAYS*]->(endNode) and disregard inbound DELAYS relationships.

2) apoc.algo.dijkstra(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', defaultValue, numberOfWantedResults) yield path, weight see the optional last parameter numberOfWantedResults - is this what you're looking for?

Heermosi commented 6 years ago
1. Have you tried to use a `>` or `<` in the relationship specification, e.g.
   `call apoc.algo.dijkstra(startNode, endNode, 'DELAYS>', 'time') yield path, weight` ?
   This should only consider paths like `(startNode)-[:DELAYS*]->(endNode)` and disregard inbound `DELAYS` relationships.

2. `apoc.algo.dijkstra(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', defaultValue, numberOfWantedResults) yield path, weight` see the optional last parameter `numberOfWantedResults` - is this what you're looking for?
  1. Fine, that's what I'm looking for. Thank you very much.
  2. I'm using the last parameter to fetch specified number of results, then sort it. I think it was the way you suggest. Whatever, 2nd problem can be solved. I just worry about the performance.

After all, thank you for your reply. Have a nice day!