I think the tags explain quite well my problem :)
I've been trying to write a Gremlin traversal to compute the connected components of the simple graph described at the end of the post.
I tried with
g.V().repeat(both('e')).until(cyclicPath()).dedup().tree().by('name').next()
obtaining
==>a={b={a={}, c={b={}}, d={c={d={}}}}, c={d={c={}}}}
==>e={f={e={}, g={f={}}}, h={f={h={}}}}
==>g={f={g={}}}
which is bad, since the cyclicPath
filter terminated the traversal starting from e
before reaching g
.
Obviously, if I remove the until
clause I get an infinite loop.
Moreover, if I use simplePath
the traverse ends after one step.
Is there any way to tell it to explore the nodes in depth-first order?
Cheers!
a = graph.addVertex(T.id, 1, "name", "a")
b = graph.addVertex(T.id, 2, "name", "b")
c = graph.addVertex(T.id, 3, "name", "c")
d = graph.addVertex(T.id, 4, "name", "d")
e = graph.addVertex(T.id, 5, "name", "e")
f = graph.addVertex(T.id, 6, "name", "f")
g = graph.addVertex(T.id, 7, "name", "g")
h = graph.addVertex(T.id, 8, "name", "h")
a.addEdge("e", b)
a.addEdge("e", c)
b.addEdge("e", c)
b.addEdge("e", d)
c.addEdge("e", d)
e.addEdge("e", f)
e.addEdge("e", h)
f.addEdge("e", h)
f.addEdge("e", g)