1 / 14

The Manhattan Tourist Problem

The Manhattan Tourist Problem. Shane Wood 4/29/08 CS 329E. Problem Summary. A tourist group in Manhattan wishes to see as many sights moving south-east from the corner of 59 th St. and 8 th Ave. to 42 nd Street and Lexington Ave. How can we achieve this using dynamic programming?.

iokina
Télécharger la présentation

The Manhattan Tourist Problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Manhattan Tourist Problem Shane Wood 4/29/08 CS 329E

  2. Problem Summary • A tourist group in Manhattan wishes to see as many sights moving south-east from the corner of 59th St. and 8th Ave. to 42nd Street and Lexington Ave. • How can we achieve this using dynamic programming?

  3. Summary (cont.) • Imagine the map as a graph with a source (59th St. and 8th Ave.) and a sink ( 42nd St. and Lexington Ave.:

  4. 8th Ave 7th Ave 6th Ave 5th Ave Madison Ave Park Ave Lexington Ave Third Ave 59th St 57th St 55th St 53rd St 51st St 49th St 47th St 45th St 43rd St 42nd St 4 1 3 2 2 4 4 4 1 By imagining vertices representing intersections and weighted edges representing street blocks, we can reduce the Manhattan Tourist Problem to what is known as the Longest Path Problem.

  5. Manhattan Tourist Problem: • Input: A weighted grid G with a starting source vertex and an ending sink vertex • Output: A longest path in G from source to sink

  6. Strategy • It is better to solve a generalized version of the MTP • Rather than solving the longest path from (0,0) (source) to (n,m)(sink for an nxm grid), we will solve (0,0) to (i,j) for 0 ≤ i ≤ n and 0 ≤ j ≤ m (an arbitrary vertex) • If (i,j)is a vertex in the longest path to the sink, the longest path to (i,j)must be contained in the longest path to the sink

  7. Exhaustive Solution • Generate ALL possible paths in grid G • Output the longest path • Not feasible for even a moderately sized graph

  8. Source 3 1 4 2 2 3 3 3 1 3 4 2 7 2 3 2 6 3 5 7 9 1 1 1 12 v 28 Sink A Greedy Algorithm • At every vertex, choose the adjacent edge with the highest weight • Easily achievable in polynomial time, but is unlikely to give the optimal solution, especially for larger graphs!

  9. S0,j 1 3 4 Si,0 2 3 2 3 3 1 3 4 2 7 2 3 2 6 3 5 7 9 1 1 1 DP Approach • For every vertex, we want to find si,j, the weight of the longest path from (0,0) to that vertex • Base Case: • Finding s0,j and si,0 for all i and j is easy

  10. s0,1 + weight of edge between (0,1) and (1,1) s1,0 + weight of edge between (1,0) and (1,1) • The tourist can now arrive at (1,1) in one of two ways: • Traveling south from (1,0), or • Traveling east from (0,1) • Once s0,j and si,0 are computed, we can determine s1,1 by comparing these two possibilities and determining the max • s1,1 = max

  11. si-1,j + weight of edge between (i-1,j) and (i,j) si,j-1 + weight of edge between (i,j-1) and (i,j) • This same logic applies more generally: • si,j = max We can thus compute every value for si,j recursively with one run through the grid

  12. si-1,j + wi,j si,j-1 + wi,j Algorithm used for DP solution • Let wi,j represent the weight of a southerly move (the weight of the edge between (i,j-1) and (i,j) ) and wi,j represent the weight of an easterly move (the weight of the edge between (i-1, j) and (i,j) ) • 1 s0,0 0 • 2 for i 1 to n • 3 si,0si-1,0 + wi,0 • 4 for j 1 to n • 5 s0,j s0,j-1 + w0,j • 6 for i 1 to n • 7for j 1 to m • 8 si,j max • 9 return sn,m Running Time: O(nxm) for an nxm grid

  13. Further analysis • Note that lines 1-5 in the algorithm are generating the base cases we use to develop later recurrence relations • We can generate the longest path by keeping track of which paths are used to generate sn,m!

  14. Questions?? Thanks!

More Related