I use neo4j database to calculate the shortest path between nodes.The whole graph include 400K nodes.I could use the shortestPath algorithm like below when I calculate the weight with addition operation, but how should I do if I wants to use multiplication operation to calculate the weight the nodes?
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;
You could map your
weight
field to alogWeight
field by taking a logarithm - then in logarithmic space addition is multiplication in regular space.Functions you can use:
https://neo4j.com/docs/cypher-manual/current/functions/mathematical-logarithmic/
Then if the shortest path you calculate (using the logarithmic weights) to a node
n
isn.ShortestDistance
you can get the product of all the weights (pre-logarithm) by doingexp(n.ShortestDistance)
.