5

Given a weighted directed multigraph, I have to find shortest path between starting vertex u to vertex v. Apart from weight, each edge also has time. The path connecting u and v cannot take more than a given maximum time. The trouble is while using Djikstra, there are chances that shortest path takes more time than the limit.

My approach is to find all valid paths between u and v and than minimize the weight. But the approach is not practical due to its high complexity.

Any ideas?

Neithrik
  • 2,002
  • 2
  • 20
  • 33
Manoj
  • 314
  • 1
  • 2
  • 12
  • 1
    I keep thinking that there might be a way to combine the two kinds of weight into one. – biziclop Apr 23 '15 at 09:36
  • 1
    How complex is your current solution? Is this a one off query or will there be repeated queries with the same source or target? Is `Θ(^3)` acceptable? – biziclop Apr 23 '15 at 09:49
  • 1
    I am also thinking of a method to combine DFS adn djikstra to solve the above mentioned problem but I haven't came up with any? – Manoj Apr 23 '15 at 11:45
  • 1
    How about using the Bellmann-Ford algorithm to calculate the minimum time distance from `u` for all vertices, which would allow you to throw away vertices (and thereby all paths that go through them) that can't be reached in the given time. That should reduce the size of your graph considerably. (And if `v` is in the discarded set, you can already say that there is no solution.) – biziclop Apr 23 '15 at 11:52

1 Answers1

0

If weights are small enough

In this case, what you can do is for each node, store all possible sums of weights that you can get on path to that node. Now you can do dijsktra on this new graph and try to minimize time over nodes which are pairs (node, weight_sum).

If times are small enough

You can do the same as in previous example, but over pairs (node, time).

General problem

I'm afraid that in general all you can do is try all possible paths, try to improve it with prunning.

Neithrik
  • 2,002
  • 2
  • 20
  • 33