How to use Apoc dijkstra procedure in a resultset?

Hi,

I am writing regarding a shortest path calculation. I hope the solution just have avoided me.

I have some nodes and edges. My all edges contain some properties but there are 2 important.
These are "width" and "distance".
I can use apoc dijkstra route calculation in the simple way and I can use "distance" property.

But couple of days ago I had to add "width" property to the edges.
In this case the simple dijkstra calculation is not good for me longer. Because I should calculate with this property as well.

My first thougt is I should create a subquery. In first step I can remove those edges which contain value 110 of "width" and the returning resultset will be useful for a second query where I can call apoc dijkstra procedure.
But unfortunatelly I can't call dijkstra procedure in a part resultset. It is called always the whole node network I guess because in the returning resultset I can find edges with value 110.

Can you recommend me some solution?
I wouldn't instist dijkstra algorithm if I can use in some other procedure "edge.width > 110" condition with distance weight.

Thank you for your help in advance!
Janos

I can think of a few options:

  1. Use cypher projection to project your graph without the nodes connected with a relationship where width > 110
  2. Temporarily change the type of the relationships that have width > 110 to a different type. Then project as you are doing now with the original relationship type, which would not include the relationships with the temp type. After projection, you would retype the relationships with their original type.
  3. Create a new relationship property to use in the shortest path algorithm. Its value would be the distance value if width <= 110 and a huge number if width > 110. Project and run shortest path algorithm. Any paths with a high costs are to be ignored.
1 Like

Hi Gary,

Thank you for your points!
I sympathize the second possibility. I implemented that idea and it's great! : )
It was tested in neo4j browser and after that in spring boot app and it works like a charm! Of course I added transaction and it is safe as well.

Thank you very much for the useful thoughts!

1 Like