0

I am using Neo4J to store a network topology and execute some graphs algorithms like Dijkstra and allSimplePaths (using apoc procedures).

I need to know if is possible use the output of allSimplePaths as input to the Dijkstra algorithm. In other words, run the Dijkstra algorithm on the subgraph returned by the allSimplePaths procedure.

My queries are:

1)

MATCH  (startNode:Hosts {IP:"10.0.0.1"}), (endNode:Hosts {IP:"10.0.0.4"})
CALL apoc.algo.allSimplePaths(startNode, endNode, 'Link2', 6 ) YIELD path
RETURN path

2)

MATCH  (startNode:Hosts {IP:"10.0.0.1"}), (endNode:Hosts {IP:"10.0.0.4"})
CALL apoc.algo.dijkstra(startNode, endNode, 'Link2', 'BANDOUT') YIELD path, weight
RETURN path, weight

So, how I bond these two queries into one? I am using Neo4j 3.0.3 and apoc 3.0.4.

cybersam
  • 63,203
  • 6
  • 53
  • 76
B. André
  • 3
  • 1
  • how do you use output off all_simple_paths as input to dijkstra ? while allSimplePaths return paths, dijkstra takes for an input start and end node, so I am not sure what are you trying to achieve – Tomaž Bratanič May 02 '17 at 15:31

1 Answers1

2

The original Dijkstra algorithm does not take a collection of simple paths (i.e., paths without repeated vertices) as input -- it just takes the starting and end vertices (and the graph) as input. The APOC procedure is an implementation of that algorithm, so there is no way to do what you request.

In fact, if you already have a collection of the simple paths between two vertices, there is no need to use the Dijkstra algorithm anyway. You just need to sum the weights of the edges in each simple path -- and the path with the smallest sum would be your result. (However, I suspect that this technique will be more expensive overall than just using the Dijkstra algorithm alone to get the result.)

cybersam
  • 63,203
  • 6
  • 53
  • 76