cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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

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

anthapu
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.

View solution in original post

4 REPLIES 4

anthapu
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.

@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?

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?

Won't it add too many relationships to already existing data set?

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.

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.