This preview shows page 1. Sign up to view the full content.
Unformatted text preview: valid path from a city s to a city t, or report that no such path exists.
Solution: We will solve this problem by transforming G = (V, E, w), the graph of
cities, roads, and toll/gas costs, into a new graph G = (V , E , w ). We will then use
Dijkstra’s algorithm to ﬁnd the desired path.
First construct the vertex set V . For each vertex v ∈ V , create three vertices in
V : vf , vh , and ve . These stand for a full tank, a half-full tank, and an empty tank,
respectively. This operation takes O(V ) time, since we iterate |V | times and create
three new vertices each time.
Next we will discuss the construction of E and w . For each edge (u, v ) = e ∈ E ,
create edges in E as follows. Create edges (uf , vh ) and (uh , ve ) to represent the
emptying of half the tank during the move from u to v . The weights on both of these
edges will be the original weight w(u, v ). This operation takes O(E ) time, since we
iterate |E | times and insert two new edges into E each time.
Finally, we will represent the cost of fueling up by creating additional edges as follows.
For every vertex v ∈ V , we ch...
View Full Document
This document was uploaded on 03/17/2014 for the course ELECTRICAL 6.006 at MIT.
- Fall '11