Gremlin - 按成本排序最短加权路径输出

问题描述 投票:0回答:1

我尝试使用Gremlin从Amazon Neptune图获得最短的加权路径,如TinkerPop食谱中所示 -

gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)).
           path().as('p').
           map(unfold().coalesce(values('weight'),
                                 constant(0.0)).sum()).as('cost').
           select('cost','p')

但是,我需要输出将按计算的成本(最低成本作为第一个输出)排序,而不是按路径中的节点数排序。

我在查询中尝试了一些order().by(..)组合但没有成功

graph gremlin traversal shortest-path amazon-neptune
1个回答
0
投票

这能满足您的需求吗?

g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)).
           path().as('p').
           map(unfold().coalesce(values('weight'),
                                 constant(0.0)).sum()).as('cost').
           order().by(select('cost')).
           select('cost','p')
© www.soinside.com 2019 - 2024. All rights reserved.