问题描述
我使用neo4j数据库计算节点之间的最短路径。整个图包括40万个节点。当我用加法运算权重时可以使用如下所示的shortestPath算法,但是如果我想使用乘法该怎么办操作来计算节点的权重?
MATCH (sourceNode:entity{name: $name})
CALL gds.alpha.shortestPath.deltaStepping.stream({
startNode: sourceNode,nodeProjection: "*",relationshipProjection: {
all: {
type: "*",properties: "weight",orientation: "UNDIRECTED"
}
},relationshipweightProperty: "weight",delta: 1.0
})
YIELD nodeId,distance
WHERE gds.util.isFinite(distance)
RETURN sourceNode.name,gds.util.asNode(nodeId).name AS aim_entity,distance
ORDER BY distance;
解决方法
您可以通过取对数将 weight
字段映射到 logWeight
字段 - 那么在对数空间中,加法就是常规空间中的乘法。
您可以使用的功能:
https://neo4j.com/docs/cypher-manual/current/functions/mathematical-logarithmic/
如果您计算(使用对数权重)到节点 n
的最短路径是 n.ShortestDistance
,您可以通过执行 {{1} }.