I have a directed acyclic graph and need to find the shortest paths with resource constraints. My constraint is that the paths selected must have a minimum number of a set resource consumed.
Currently I am using Yen's K Shortest Path algorithm to calculate K shortest paths and then only accept those that satisfy my constraint. The issue here is in guessing K, as if it is incorrectly chosen, it is possible that no feasible paths will be found.
I have found quite a lot of literature on this topic, this provides a good overview I think. However, I am struggling to make sense of it and find a concise algorithm that is able to be implemented (I am using Python, however any clear algorithmic ideas would be great).
I understand that this problem is NP-Complete, and as such I am interested in any good approximation algorithms as well as exact approaches.
Anyone have any good recommendations?
What you can do is to transform your graph (V,E)
into (V',E')
where
P(v)
is the price of the original node v
R
is the maximum resource use.V' = {(v,k) | v in V and k in [0..R]}
E'((v,k),(w,l)) = E(v,w) and k+P(w)=l
Then you do a dijkstra search from (v0,P(v0))
. If it was possible to find a path to v1
, given the limit, the shortest distance to it, will be the shortest among the (v1,k)
vertices.
You obviously don't create the actual expanded graph. What would be going on in your modified dijkstra is that in addition to the distance so far, you would keep the resource use so far as well. You would only follow a path if it didn't exceed the limit. And instead of keeping a dist[v]
you would keep dist[v,k]
representing the shortest path to v so far, using exactly k
resources.
If your resource bound is very large, this can potentially grow as big. Hence the NP completeness. However if your resource bound is small, or you don't mind rounding of to nearest 10, 100 or 1000, it will run in fast polynomial time.
Especially if you implement the optimization of stopping once you've reached a useable (v1,k)
.