Is there better way than a Dijkstra algorithm for finding fastest path that do not exceed specified cost

佐手、 提交于 2019-12-11 00:53:48

问题


I'm having a problem with finding fastest path that do not exceed specified cost. There's similar question to this one, however there's a big difference between them. Here, the only records that can appear in the data are the ones, that lead from a lower point to a higher point (eg. 1 -> 3 might appear but 3 -> 1 might not) (see below). Without knowing that, I'd use Dijkstra. That additional information, might let it do in a time faster than Dijkstras algorithm. What do you think about it?

Let's say I've got specified maximum cost, and 4 records.

// specified cost
    10 
// end point
    5
//(start point) (finish point) (time) (cost)
    2 5 50 5
    3 5 20 9
    1 2 30 5
    1 3 30 7
// all the records lead from a lower to a higher point no.

I have to decide, whether It's possible to get from point (1) to (5) (its impossible when theres no path that costs <= than we've got or when theres no connection between 1-5) and if so, what would be the fastest way to get in there.

The output for such data would be:

80 // fastest time
3 1 // number of points that (1 -> 2)  -> (2 -> 5)

Keep in mind, that if there's a record saying you can move 1->2

1 2 30 5

It doesnt allow you to move 2<-1.


回答1:


For each node at depth n, the minimum cost of path to it is n/2 * (minimal first edge at the path + minimal edge connecting to the node) - sum of arithmetic series. If this computation exceeds the required maximum, no need to check the nodes that follow. Cut these nodes off and apply Dijkstra on the rest.



来源:https://stackoverflow.com/questions/13414769/is-there-better-way-than-a-dijkstra-algorithm-for-finding-fastest-path-that-do-n

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