Attaching Weights between the Nodes in Dijkstra Algorithm

How do I attach weights between the nodes to run the Dijsktra algorithm in the below code snippet?

Hi @anberarif, can you elaborate a bit more?
If you want to have different weights between nodes and not a constant of 1, you need to have a weight (similarly called property representing weight) on the relationships between nodes. In the example above, when you’re creating a relationship in the third row of your query, you would have:
CREATE (p1)-[:FRIENDS_WITH {{weight: {row[2]}}}]->(p2)
if the weight is saved in the third column of the dataset_updated.csv file.

Then, when calling Dijkstra, you can use
[:FRIENDS_WITH * wShortest (e, v | e.weight) count]

Not sure if that’s what you asked for or something else, so please do let me know :smile:

1 Like

Hi @katarinasupe :smile: Yeah this was what I was asking for.
Thanks for resolving my query.

1 Like

No problem and good luck! :smile:

1 Like