Variations of Dijkstra's Algorithm for graphs with two weight properties

蹲街弑〆低调 提交于 2019-12-06 11:17:04

Say you want to optimize simultaneously two criteria: distance and attractiveness (and say path attractiveness is defined as the attractiveness of the most attractive edge, although you can think of different definitions). The following variation of Dijkstra can be shown to work, but I think it is mainly useful where one of the criteria takes a small number of values - say attractiveness is 1, ..., k for some small fixed k (smaller i is better).

The standard pseudocode for Dijsktra's algorithm uses a single priority queue. Instead use k priority queues. Priority queue i will correspond in Dijkstra's algorithm to the shortest path to a node v ∈ V with attractiveness i.

Start by initializing that each node is in each of the queues with distance (because, initially, the shortest path to v with attractiveness i is infinite).

In the main Dijkstra loop, where it says

 while Q is not empty

change it to

 while there is an i for which Q[i] is not empty
     Q = Q[i] for the lowest such i

and continue from there.

Note that when you update, you pop from queue Q[i], and insert to Q[j] for j ≥ i.

It's possible to modify the proof of Dijkstra's relaxation property to show that this works.

Note that you will obtain up to k |V| results, as per node and attractiveness, you can have the shortest distance to the node with the given attractiveness.

Example

Taking an example from the comments:

So basically if a path has a total no-coverage miles of >10, then we go for another path.

Here, e.g., assuming the miles are integers (or can be rounded to integers), we could create 11 queues: queue i corresponds to the shortest distance with i no-coverage miles, except for 10, which corresponds to 10-or-higher no-coverage-miles.

At some point of the algorithm, say all queues are empty below queue 3. We pop queue 3, and update the vertex's neighbors: this might update, e.g., some node in queue 4, if the distance from the popped node to the other node is 1.

As the algorithm runs, it outputs mappings of (node, no-coverage-distance) → shortest distance. Here, you could decide that you discard all mappings for which the second item in the pair is 10.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!