cancel
Showing results forΒ
Did you mean:Β

## Why do different modes of the same algorithm produce different results?

Node Clone

Why do different modes of the same algorithm produce different results?

### Dijkstra stream mode

``````match (source:Node1 {start_marker:1})
call gds.allShortestPaths.dijkstra.stream('orient_undirected__agr_single', {sourceNode: source})
yield index, sourceNode, targetNode, nodeIds, path
return index, sourceNode, targetNode, nodeIds, path
``````

### Dijkstra write mode

``````match (source:Node1 {start_marker:1})
call gds.allShortestPaths.dijkstra.write('orient_undirected__agr_single',{
sourceNode: source,
writeRelationshipType: 'PATH',
writeNodeIds: true,
})
YIELD relationshipsWritten
RETURN relationshipsWritten
``````

`match (n) return n`

1 ACCEPTED SOLUTION
Graph Fellow

This method as per documentation creates a relationship between start node and all the target nodes with cost and node id's in between start and target.

From that perspective this graph is correct.

Having multiple relationships between same nodes does not add any perspective to shortest path.

4 REPLIES 4
Graph Fellow

This method as per documentation creates a relationship between start node and all the target nodes with cost and node id's in between start and target.

From that perspective this graph is correct.

Having multiple relationships between same nodes does not add any perspective to shortest path.

Node Clone

@anthapu

Hi anthapu,
thank you for the info!
Do you think you could suggest which algorithm would be the best to keep all nodes on each path?

Graph Fellow

I guess I am not understanding your issue correctly. The stream option does give you all the paths. Do you need to create a set of relationships from START and END node?

What the write is doing is telling you between node1 and node2 if PATH relationship exists, what other nodes are in between to reach to node2 in a shortest path.

Node Clone

Hi @anthapu,

The idea was to reduce all those paths `PATH_*` to a single `PATH`.

From that graph:

I wanted to reach the following state:

(don't take into consideration different labels, only what matters here are the relationships)

I thought I can achieve that by simply removing those paths `PATH_*`.
Then, I've learnt that they are virtual objects, and I cannot work on them directly. I need to convert them first to the real objects.
So I run the algorithm in the write mode believing it will store all `PATH_*`, but the result was different.

I've found another algorithm, but I think I don't quite understand why STREAM shows all nodes in the path, and WRITE just returns the path and additionally creates self-relationship tho the starting node.

Nodes 2022

NODES 2022, Neo4j Online Education Summit

OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.

Neo4j Resources