繁体   English   中英

根据路径编辑 sack() 值

[英]edit sack() value depending on path

我有通往两个目标的三个路径。 所有边都有不同的强度,我用 sack() 收集它们。 我想比其他路径更重地权衡一些路径(与边缘强度无关)。 在此示例中:通过“重要”顶点的路径应具有因子 5,通过“不重要”因子的路径应具有 0.5。

我将如何做到这一点?

到目前为止我有这个查询,因为按目标顶点对结果进行分组并添加路径权重对我来说很重要。

    .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)

我试图用 math() 影响 sack 值,但它只影响“打印”值,而不影响 sack 内的值。 以下查询显示了这一点,但我无法按 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')
    )

数据:

%%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'))

(我的代码使用 gremlin 在 Neptune 上运行:{'version': 'tinkerpop-3.4.11'})

您可以将重要/不重要路径中的麻袋乘以常数。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM