Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortest Path With Priority Nodes

I have to find shortest path I guess djistra's algorithm is efficient for that. But I have added constraint that nodes have priority other than distance between them. So considering priority we have to find the shortest path. Can anyone spread some light on this. Thanks in advance.

like image 910
amaldec23 Avatar asked Dec 04 '25 18:12

amaldec23


1 Answers

Let's say you have a graph G = (V, E), where V is the set of vertices, E is the set of edges. Since you want to introduce another parameter called priority in a set P, defined as P = {pi | pi is the priority of vertex vi}.

You can update your distance as d_ij_new = d_ij - (pi + pj). This will ensure that the distance decreases as a function of priorities of the vertices being considered. You will also need to make sure the distance does not go negative. To ensure that, add 2 * pmax to all the weights (pi + pj < 2 * pmax).

enter image description here

like image 84
nikhilbalwani Avatar answered Dec 06 '25 09:12

nikhilbalwani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!