A path analytics question....

19 views
Skip to first unread message

unreal...@googlemail.com

unread,
Apr 7, 2017, 5:12:05 PM4/7/17
to Neo4j

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:  match (n:Entity { name: 'xyz' })

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

Wayne



Michael Hunger

unread,
Apr 8, 2017, 5:22:33 AM4/8/17
to ne...@googlegroups.com
You can do

MATCH (n:Entity) where n.name IN {names}
WITH collect(n) as nodes
UNWIND nodes as n
UNWIND nodes as m
MATCH path = allShortestPaths( (n)-[*..4]-(m) )
RETURN path


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

unreal...@googlemail.com

unread,
Apr 9, 2017, 3:45:17 AM4/9/17
to Neo4j
Thanks Michael.

Playing around with this I note that I can also write:
.
.
UNWIND nodes as o
UNWIND nodes as p
MATCH path=(n)--(m)--(o)--(p)

Which is another case that I'm interested in.

Do you know whether anyone has written an Neo4j expression to address the travelling salesman problem ?
My spin is,   instead of looking at a property distance value,    to find, from a given set of nodes,   which node other provides the least node traversals to all other nodes...

Wayne 
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages