preventing cycles

84 views
Skip to first unread message

Wes Freeman

unread,
Aug 7, 2012, 4:30:44 PM8/7/12
to ne...@googlegroups.com
What's the best way to prevent cycles in a graph? I'm building a graph that is usually more like a tree, but sometimes nodes point up to higher levels in the tree (direction matters). I want to make sure that when that happens, the higher level node is not a parent of the current node.

Say I have this graph: http://console.neo4j.org/r/en0t9x. I'm currently at node D1, and I successfully created a link to B3, but I would want to prevent links from D1 to B1 or A, for example. The only thing I have in my process is a list of node names I "want" to connect to, and that list might contain D1 or B1.

Thanks,
Wes

Michael Hunger

unread,
Aug 7, 2012, 4:57:26 PM8/7/12
to ne...@googlegroups.com
Wes,

you can use paths as predicates 

e.g.

start current= ..., target= ...
where NOT(current<-[:linked*]-target)
create current-[:linked]->target

HTH

Michael

Wes Freeman

unread,
Aug 7, 2012, 5:00:56 PM8/7/12
to ne...@googlegroups.com
Awesome, thanks. I'll give that a try.

Wes
Reply all
Reply to author
Forward
0 new messages