天天看點

All shortest paths between a set of nodes

Consider a number of arbitrary nodes, A,B,C,D,E,F,…​..

I wish to return all of the shortest paths between these nodes.The nodes may have many edges between them, but anticipate a maximum of 4.

The graph is complex and non hierarchical (if this makes sense – any node may point to any other node).

A typical node has the form: ​

<code>​match (n:Entity { name: 'xyz' })​</code>​

How would I write the match expression to return the shortest paths between the above nodes, in no specific order?

Find the set of nodes using an indexed lookup operation

Collect them into a list

Unwind the list twice, once for every side of the path

Remove inverse pairs by id comparison

match and return the paths