How would I optimally solve a graph theory problem, where the edge weight changes on every other, or even third hop? Could I still use some kind of modified Dijkstra's algorithm?
Asked
Active
Viewed 136 times
1 Answers
1
You can build a new graph that encodes the changing costs (though practically speaking, it's probably better not to construct the new graph explicitly).
Given a graph like
1
A --> B
| / |
2 | /5 | 4
v < v
C <-- D
3
each vertex gives rise to two vertices, and each arc gives rise to two arcs. The arcs go from the original to the copy at original weight and from the copy to the original at double weight.
1 5 3
A ---> B' B ---> C' D ---> C'
2 10 6
A' ---> B B' ---> C D' ---> C
2 4
A ---> C' B ---> D'
4 8
A' ---> C B' ---> D
Now search from either the source or its copy depending on whether the first hop is doubled, looking for cheapest path to the destination or its copy.

David Eisenstat
- 64,237
- 7
- 60
- 120
-
Would this work only for every other edge weight doubled? Or could it be modified and applied to every nth hop being doubled? For example every third hop, or fourth hop? Would you accomplish this by adding another graph on top? I think that makes sense. Thank you so much! – Sauhaarda Feb 12 '17 at 19:52
-
@Sauhaarda The general idea is, given a graph (V, A) where each kth hop should be doubled, construct a new graph with vertices V x {0, ..., k-1} and arcs {(v, j) -> (w, (j+1) mod k) | v -> w in A and j in {0, ..., k-1}}, where the weight of (v, j) -> (w, (j+1) mod k) is 2x the weight of (v, w) if j =
else 1x. – David Eisenstat Feb 12 '17 at 19:54 -
I +1ed your post, but since I have very few reputation, there was no effect. – Sauhaarda Feb 12 '17 at 19:58