Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shortest path with dynamic edge cost (algorithm)

I'm looking for an algorithm that can find the shortest path between two nodes in an undirected graph with a cost which is dynamic. By dynamic, I mean that the cost on edge is dependent on the next (future) step. For example, in a graph like that:

dynamic edge cost in shortest path problem

I'm looking for the shortest path from "a" to "e" but the cost of "a" to "b" depends on next step. If I go to c, it is 7, and if I go to d, it is 9.

My question is: Is there an algorithm which solves that problem?

like image 202
trojek Avatar asked Apr 06 '14 18:04

trojek


People also ask

Which algorithms uses dynamic programming for shortest path problems?

The Floyd Warshall Algorithm is for solving all pairs shortest path problems.

How do you find the shortest path in dynamic programming?

Dynamic Programming approach We fill the table in bottom up manner, we start from e=0 and fill the table till e=k . Then we have our shortest path cost stored in dp[u][v][k] where u is source, v is destination and k is number edges between path from source to destination.

Which algorithm is used to find shortest path of an algorithm?

Dijkstra's Algorithm finds the shortest path between a given node (which is called the "source node") and all other nodes in a graph.

What is the best algorithm for shortest path?

The most important algorithms for solving this problem are: Dijkstra's algorithm solves the single-source shortest path problem with non-negative edge weight. Bellman–Ford algorithm solves the single-source problem if edge weights may be negative.


1 Answers

Reduce the problem to 'regular' shortest path problem

Create dummy vertices b1,b2 (instead of b), and the edges:

(a,b1,7), (b1,c,6), (a,b2,9), (b2,d,5)

The rest of the edges and vertices remain as they originally were.

Now, run regular shortest path algorithm (Dijkstra / Bellman Ford) from the source to the target.

(Repeat the process for any 'conditional' weight edges).

like image 157
amit Avatar answered Sep 17 '22 23:09

amit