我认为标签很好地解释了我的问题:)
我一直在尝试编写一个 Gremlin 遍历来计算帖子末尾描述的简单图的连通分量。
我试过了
g.V().repeat(both('e')).until(cyclicPath()).dedup().tree().by('name').next()
获得
==>a={b={a={}, c={b={}}, d={c={d={}}}}, c={d={c={}}}}
==>e={f={e={}, g={f={}}}, h={f={h={}}}}
==>g={f={g={}}}
这很糟糕,因为cyclicPath
过滤器从e
到达之前终止了遍历g
。显然,如果我删除该until
子句,我会得到一个无限循环。此外,如果我simplePath
在一步后使用遍历结束。有没有办法告诉它以深度优先顺序探索节点?
干杯!
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)