简体   繁体   English

根据路径编辑 sack() 值

[英]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.

相关问题 添加不同路径的Sack值 - add Sack value of different paths “设置交集”与“有路径”和 Sack() - 'set intersection' vs. 'has path to' and Sack() Terraform - 确保根据是否还设置了另一个值来设置值 - Terraform - ensure value is set depending on if another value is also set 如何在 Firestore 文档的 map 中添加或编辑特定值? - How to add or edit specific value within a map on a firestore document? BigQuery 根据某个字符串值在列中出现的次数将所有指标分成 n 个相等的部分 - BigQuery to split the all the metrics into n equal parts depending on the number of times a certain string value appears in a column 在 Security Firstore Rules 中是否可以只让用户根据字段值读取数据? - in Security Firstore Rules does it possible to only make users to read data depending on field value? 参数“documentPath”的值不是有效的资源路径。 路径必须是非空字符串 - Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string SQL:根据另一列中是否至少有一个值满足特定条件来创建列 - SQL: Creating a column depending on whether there is at least one value in another column that fulfils a certain condition or not 参数“documentPath”的值不是有效的资源路径。 Firebase 云函数 - Value for argument "documentPath" is not a valid resource path. Firebase Cloud Functions Azure 数据工厂:存储事件触发器的动态路径值 - Azure Data Factory: Dynamic path value for the Storage Event Trigger
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM