incubator-hugegraph
incubator-hugegraph copied to clipboard
求助:从一点出发找出n步内可以形成的环路怎么用gremlin写啦?
如题,求高手指点下怎么求环路(如a-->b-->c-->a)
可以使用 repeat + times + cyclicPath 试试。
这是大概的框架:
g.V().has('name', 'a').repeat(out()).times(n).cyclicPath().path()

@Linary 感谢您的指导,我也用这种类似的写法实现了一个,但结果跟你的一样,中间会来回重复 我的代码如下: g.V('貂蝉') .repeat(outE().inV()) .until(loops().is(gte(6))).dedup().hasId('貂蝉') .cyclicPath().path()
试试这个呢。
g.V('貂蝉')
.repeat(out())
.until(id().is('貂蝉'))
.cyclicPath()
.path();
@Linary 执行不了
@1315861791 抱歉,语句写的有问题,应该是:
g.V('貂蝉').repeat(out()).until(hasId('貂蝉')).cyclicPath().path()
如果这样还不行,那就找一个“貂蝉这个顶点有的属性”,将判定条件换成对该属性的判断。比如“貂蝉”这个点有一个属性“name”也叫“貂蝉”,那就:
g.V('貂蝉').repeat(out()).until(has('name', '貂蝉')).cyclicPath().path()
@Linary ganxie感谢大神!!!
