我正在尝试使用 Neo4J 和 APOC Lib 生成随机游走。 我的目标是计算具有一定距离长度的随机游走。 在我的数据库模型中,这些关系提供了“距离”属性。如何在计算中包含此参数?这样我就能得到一条不受步数限制而是受距离限制的路径? (节点=位置,关系=连接)
这是我当前的查询。
MATCH (m:location {osmid:33633426})
CALL apoc.path.expandConfig(m, {
relationshipFilter: "connection",
minLevel: 1,
maxLevel: 50,
uniqueness: "RELATIONSHIP_GLOBAL"
})
YIELD path
WITH path, length(path) AS hops
WHERE hops >= 10
RETURN path, hops
ORDER BY hops
Limit 1;
您可以根据关系类型(:连接)中找到的距离总和添加过滤器
MATCH (m:location {osmid:33633426})
CALL apoc.path.expandConfig(m, {
relationshipFilter: "connection",
minLevel: 1,
maxLevel: 50,
uniqueness: "RELATIONSHIP_GLOBAL"
})
YIELD path
WITH path,
REDUCE (totdistance=0, dist in relationships(path) |
totdistance + dist.distance ) AS totaldistance
WHERE totaldistance >= 10
RETURN path, totaldistance
ORDER BY totaldistance
LIMIT 1;