cancel
Showing results forΒ
Did you mean:Β

## Can Dijkstra Single-Source be implemented on data with different labels?

Node Clone

I'm newb on Neo4j, and I'm studying following Dijkstra Single-Source algorithm from the docs:

``````MATCH (source:Location {name: 'A'})
CALL gds.allShortestPaths.dijkstra.stream('myGraph', {
sourceNode: source,
relationshipWeightProperty: 'cost'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs, path
RETURN
index,
gds.util.asNode(sourceNode).name AS sourceNodeName,
gds.util.asNode(targetNode).name AS targetNodeName,
totalCost,
[nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
costs,
nodes(path) as path
ORDER BY index
``````

Would it be possible to apply this algorithm to dataset with different properties?
In the given example all nodes have the same property `name`.

1 ACCEPTED SOLUTION
Neo4j

Hey @marcelix161 ,
yes you can also use the algorithm with nodes that have different properties.
The `name` property is used here to give a easy-to-read description of the node.
FYI: `gds.util.asNode(sourceNode)` gives you the whole node (see Utility functions - Neo4j Graph Data Science).

Neo4j

Hey @marcelix161 ,
yes you can also use the algorithm with nodes that have different properties.
The `name` property is used here to give a easy-to-read description of the node.
FYI: `gds.util.asNode(sourceNode)` gives you the whole node (see Utility functions - Neo4j Graph Data Science).

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