graph theory - Shortest path with a fuel tank -
this homework question , i'd happy guidance.
let g=(v,e) undirected graph each vertex represents city, , edges have weights represents travel distances. of cities have gas stations in them. car starts vertex s gas tank sufficient travel length l. need find shortest path between s , t car won't run out of gas.
my main thought use floyd–warshall algorithm changes. when calculate shortestpath(i,j,0) assign w(i,j) if has gas station , l-w(i,j) > 0 , , infinity otherwise. however, next steps, don't know how add current fuel status calculations.
thanks.
make new weighted graph vertices: s, t , cities (c) gas station.
edges:
s-c,cc, if there shortest path betweens,chas length<= l,c1-c2,c1,c2c, lengthc1-c2 <= l,c-t,cc, lengthc-e <= l,s-t, if lengths-t <= l.
and edge weight set length v1-v2.
standard dijkstra on graph should return skeleton of shortest path looking on original graph.
it possible crate new graph 'iteratively' when dijkstra asks edges on boundary vertices. like, first create s-c , s-t edges (and vertices), , if there demand c1-c2 , c-t add these vertices , edges graph.
Comments
Post a Comment