2

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.

Patryk
  • 3,042
  • 11
  • 41
  • 83
  • I'd guess fastest path not longer than x is a pretty common problem. I bet I've seen it discussed on Wikipedia. I'll try to look it up. +1 in the meantime – John Dvorak Nov 16 '12 at 10:33

1 Answers1

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.

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85