neo4j-contrib / neo4j-graph-algorithms

Efficient Graph Algorithms for Neo4j
https://github.com/neo4j/graph-data-science/
GNU General Public License v3.0
767 stars 196 forks source link

Write total cost of shortest path to property #912

Open szarnyasg opened 4 years ago

szarnyasg commented 4 years ago

I am using the latest versions (Neo4j 3.5.8, Algorithm library 3.5.8.0).

Given a simple two-node graph:

CREATE ({VID: 1})-[:EDGE {weight: 0.2}]->({VID: 2})

I'd like to run an SSSP algorithm and save the total cost of the paths to property SSSP.

MATCH (startNode {VID: 1}), (endNode)
CALL algo.shortestPath(startNode, endNode, 'weight', {write: true, writeProperty: 'SSSP', direction: 'OUTGOING'} )
YIELD nodeCount, totalCost, loadMillis, evalMillis, writeMillis
RETURN endNode.VID, totalCost

The results are correct:

╒═════════════╤═══════════════════╕
│"endNode.VID"│"totalCost"        │
╞═════════════╪═══════════════════╡
│1            │-1.0               │
├─────────────┼───────────────────┤
│2            │0.20000000298023224│
└─────────────┴───────────────────┘

But the propery contains the traversal level and not the total cost:

MATCH (n)
RETURN n.VID, n.SSSP
╒═══════╤════════╕
│"n.VID"│"n.SSSP"│
╞═══════╪════════╡
│1      │0       │
├───────┼────────┤
│2      │1       │
└───────┴────────┘

Is there a way to write the total cost to the property?