我设法用Gremlin做到了这一点 麻袋 :
gremlin> g.withSack(a.value('amount')). V(a).repeat(outE('drain').sack(mult).by('factor'). inV().property('amount', sack())). until(__.outE('drain').count().is(0)).iterate() gremlin> g.V().valueMap() ==>[amount:[100],name:[a]] ==>[amount:[50.0],name:[b]] ==>[amount:[5.00],name:[c]]
我初始化了“袋值”等于顶点“a”中的“量”并开始遍历那里迭代地遍历我们繁殖的“排水”边缘(即 mult )“排水”边缘上“因子”属性的袋中值。然后麻袋通过分配到下一个顶点 property() 步。
mult
property()
请注意,您可以使用适当的循环语义来控制“排水”(即您想要走多远的链路) repeat 。现在它使用 until() “没有更多外向的边缘”。但是你也可以按照以下步骤终止:
repeat
until()
gremlin> g.withSack(a.value('amount')). V(a).repeat(outE('drain').sack(mult).by('factor'). inV().property('amount', sack())). times(1).iterate() gremlin> g.V().valueMap() ==>[amount:[100],name:[a]] ==>[amount:[50.0],name:[b]] ==>[amount:[0],name:[c]]