簡體   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