[英]edit sack() value depending on path
I have three paths leading to two goals.我有通往两个目标的三个路径。 All edges have a different strength and I collect them with sack().所有边都有不同的强度,我用 sack() 收集它们。 I want to weigh some of the paths more heavily than the others (independent of the edge strength).我想比其他路径更重地权衡一些路径(与边缘强度无关)。 in this sample: the paths via an 'important' vertex, should have a factor 5, those via 'unimportant' factor 0.5.在此示例中:通过“重要”顶点的路径应具有因子 5,通过“不重要”因子的路径应具有 0.5。
how would I accomplish that?我将如何做到这一点?
I have this query so far, because it is important for me to group the results by goal-vertex and add the path weights.到目前为止我有这个查询,因为按目标顶点对结果进行分组并添加路径权重对我来说很重要。
.union(
//all paths via important nodes
outE().has('weight').sack(mult).by('weight')
.inV().hasLabel('important')
.outE().has('weight').sack(mult).by('weight')
.inV(),
//all paths via UNimportant nodes
outE().has('weight').sack(mult).by('weight')
.inV().hasLabel('unimportant')
.outE().has('weight').sack(mult).by('weight')
.inV()
)
.valueMap(true)
.group().by().by(sack().sum())
.unfold()
.order().by(values, desc)
.project('alg', 'rank', 'map').by(constant('#1')).by(values).by(keys)
I tried to influence the sack value with math(), but it only influences the 'print' value, not the value inside the sack.我试图用 math() 影响 sack 值,但它只影响“打印”值,而不影响 sack 内的值。 The following query shows this, but I can't group and sort by vertexId and so on...以下查询显示了这一点,但我无法按 vertexId 等进行分组和排序......
g.withSack(1.0f).V('v0')
.union(
//all paths via important nodes
outE().has('weight').sack(mult).by('weight')
.inV().hasLabel('important')
.outE().has('weight').sack(mult).by('weight')
.inV()
.sack().math('_ * 5'),
//all paths via UNimportant nodes
outE().has('weight').sack(mult).by('weight')
.inV().hasLabel('unimportant')
.outE().has('weight').sack(mult).by('weight')
.inV()
.sack().math('_ * 0.5')
)
data:数据:
%%gremlin
g.addV('start').property(id, 'v0')
.addV('important').property(id, 'v1')
.addV('goal').property(id, 'v2')
.addV('unimportant').property(id, 'v3')
.addV('goal').property(id, 'v4')
.addE('link').property('weight', 0.4).from(V('v0')).to(V('v1'))
.addE('link').property('weight', 0.4).from(V('v1')).to(V('v2'))
.addE('link').property('weight', 0.4).from(V('v2')).to(V('v3'))
.addE('link').property('weight', 0.5).from(V('v0')).to(V('v3'))
.addE('link').property('weight', 0.5).from(V('v3')).to(V('v2'))
.addE('link').property('weight', 0.5).from(V('v1')).to(V('v4'))
(my code runs on Neptune with gremlin: {'version': 'tinkerpop-3.4.11'}) (我的代码使用 gremlin 在 Neptune 上运行:{'version': 'tinkerpop-3.4.11'})
You can multiply the sack in the important/unimportant path by the constant.您可以将重要/不重要路径中的麻袋乘以常数。
gremlin> g.withSack(1.0f).V('v0').union(
......1> outE().has('weight').sack(mult).by('weight')
......2> .inV().hasLabel('important')
......3> .outE().has('weight').sack(mult).by('weight')
......4> .inV().sack(mult).by(constant(5)),
......5> outE().has('weight').sack(mult).by('weight')
......6> .inV().hasLabel('unimportant')
......7> .outE().has('weight').sack(mult).by('weight')
......8> .inV().sack(mult).by(constant(0.5))
......9> ).
.....10> valueMap(true).
.....11> group().by().by(sack().sum()).
.....12> unfold().
.....13> order().by(values, desc).
.....14> project('alg', 'rank', 'map').by(constant('#1')).by(values).by(keys)
==>[alg:#1,rank:1.000,map:[id:v4,label:goal]]
==>[alg:#1,rank:0.9250,map:[id:v2,label:goal]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.