Shortest path with negative weights

I was reading the k-shortest path and it said we can’t use negative weights because of Dijkstra’s algorithm. I was wondering if there is a optimized way so we can use negative weights on edges and find shortest paths.

1 Like

hi, i don’t know what you are talking about but im interested, can you maybe elaborate further? maybe i also misunderstood some words

Maybe what you are looking for is the facets feature?

But I don’t recommend them. What we all are doing, is to use intermediate nodes to represent relationships. Yes this is kinda dumb since this isn’t how it shall be in a graphDB, but it makes things easier and uncomplicated.

e.g if you have tweets users and likes, you create in your schema for ‘likes’ an own type, so a like will be basically an own node which represents the relationship. it could contain fields like ‘post: [Post]’ ‘likedBy: [User]’ ‘Time: Datetime’ and so on. With this, it is very easy to calc how much likes a post has, since counting the nodes of an edge is very fast.

With intermediat-nodes it would be much easier to calc your weight stuff with DQL.

if you are interested in ‘weights’ read this recommendation engine tutorial for dgraph: