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, c c, if there shortest path between s , c has length <= l,
  • c1-c2, c1, c2 c, length c1-c2 <= l,
  • c-t, c c, length c-e <= l,
  • s-t, if length s-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

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -