290 likes | 399 Views
Search Algorithms Winter Semester 2004/2005 17 Jan 2005 12th Lecture. Christian Schindelhauer schindel@upb.de. Spatial Searching. Prolog: Searching with some help Searching with total Uncertainty Nearsighted Search The Cow Path Problem The Concept of Competitive Analysis
E N D
Search AlgorithmsWinter Semester 2004/200517 Jan 200512th Lecture Christian Schindelhauer schindel@upb.de
Spatial Searching • Prolog: Searching with some help • Searching with total Uncertainty • Nearsighted Search • The Cow Path Problem • The Concept of Competitive Analysis • Deterministic Solution • Finding a Shoreline • Probabilistic Solution • The Wall Problem • Farsighted Search • The Watchman Problem • How to Learn your Environment
The Cow-Path Problem • Given • A near-sighted cow • A fence with a gate • The cow does not know the direction • Task • Find the exit as fast as possible ???
Competitive Analysis • How to evaluate the online solution • Classical approach: • Worst-case time • This is always n for a fence of length n • Average case • This is not better • Competitive Analysis • Compare the cost of the solution of an instance x • CostAlg(x) • to the best possible offline solution (unknown to the cow) • Costoffline(x) • Minimize the competitive ratio =
Solution of the Cow Fence Problem Deterministic Cow-Path • dir left • for i 0 to log n do • go 2i steps to direction dir • go 2i steps back to the origin • revert direction dir • od Theorem [Baeza-Yates, Culberson, Rawlins, 1993] The deterministic Cow-Path algorithm has a competitive ratio of 9. This competitive ratio is optimal.
Performance of the Cow-Path Algorithm • Performance of the best (offline) strategy: d • where d is the shortest way to the exit • Worst case of the Cow-Path Algorithm • d = 2x+1 • Let d’=d-1 • Number of steps before finding the exit: 1+1+2+2+4+4+...+d’/2+d’/2+d’+d’+2d’+2d’+d’+1 = 9 d’-1 = 9 d - 10 ... d’/4 d’/2 Exit d’ 2d’ d’ 2d’ d’+1
The Shoreline Problem Problem description • A boat is lost in a half ocean with a linear shoreline • No compass on board • No sight because of dense fog • The distance to the shoreline is unknown Task • Find the coast as fast as possible ?
The Spiral Solution for the Shoreline ProblemBaeza-Yates, Culberson, Rawlins, 1993 Solution: • Use logarithmic spiral obeying • where r is the polar radius from the starting point • and is the polar angle • Numerical optimization leads to a competitive optimal ratio for k=1.250... • The shoreline problem can be solved using the logarithmic spiral method with competitive ratio 13.81... k2 1
Searching for a point in a Grid • Problem: • Find a spot in a grid without knowing the coordinates • (finding the restaurant in New York without policemen) • Solution: • Use a spiral covering all points in Manhattan distance 1,2,3,4,... • Theorem [Baeza-Yates, Culberson, Rawlins, 1993] • Using the spiral method this problem can be solved with competitive ratio 2d, where d is the Hamming distance between start and target. • This competitive ratio is optimal.
Search for a point in m Concurrent Rays Problem: • A robot is at the meeting point of m rays • It has to find a point on one of the rays • Find the shortest path Variants • Variant: the distance n is known: Then a (2m-1) competitive (deterministic) algorithm optimally solves the case • Variant: distance is not known • Visit in round i, i+m, i+2m, .. ray i • no other ordering can improve the ratio • Perform in each ray test • such that ray 1+(i mod m) is searched f(i) steps deep. • Observe for all i>m for all reasonable algorithms:
Spiral Search Cow Spiral-Search-Cow • i 0 • while bull not found do • i i+1 • explore f(i) steps of ray (i mod m)+1 • return to the starting point • od Theorem The spiral search cow algorithm has a competitive ratio of Proof: Worst case: bull in depth f(i)+1
The spiral search cow algorithm has a competitive ratio of Theorem Proof: Worst case: bull in depth f(i)+1 Steps of spiral-search-cow: Competitive ratio:
Theorem: The Spiral-Search-Cow is optimal up to a constant term o(1). Proof: Visit in round i, i+m, i+2m, .. ray i no other ordering can improve the ratio Perform in each ray test such that ray 1+(i mod m) is searched f(i) steps deep. Observe for all i>m for all reasonable algorithms: Compute the competitive ratio by Consider the constant c upper bounding Some (involved) analysis shows that this constant is minimal for which matches exactly the behavior of the spiral search cow
Deterministic and Probabilistic Competitive Ratio Deterministic Competitive Analysis Compare the cost of the solution of an instance x CostAlg(x) to the best possible offline solution (unknown to the cow) Costoffline(x) Minimize the competitive ratio Probabilistic (Randomized) Competitive Analysis Allow the algorithm to use random input Compare the cost of the expected solution of an instance x E[CostAlg(x)] to the best possible offline solution independent from the random numbers unknown to the algorithm Costoffline(x) Minimize =
Why Randomness Helps 11:5= 2.2 43:7= 6.1.. 42:6= 7 11:5= 2.2 10:4= 2.5 9:3= 3 8:2= 4 1:1= 1 - 3:1= 3 4:2= 2 19:3= 6.3.. 20:4= 5 21:6= 3.5 22:7= 3.1.. 23:8= 2.8.. ... • Expected probabilistic competitive ratio: 6 • Optimal deterministic ratio: 9
Smart Cow [Kao, Reif, Tate] 5.repeat Explore path (p) up to distance d d d r p p mod m +1 until target found Theorem For any r>1 Smart Cow has a competitive ratio of Let c:= minr>1 (1+r)/ln r and let r* be r minimizing this term Theorem Smart Cow is the optimizes the randomized competitive ratio of the cow and the fence problem for r=r* with ratio 1+c = 4.59112..
The Wall Problem Instance: A set of non-overlapping oriented rectangles multiples of the unit size in a d x d - square Player is nearsighted If we hit a wall we immediately know its geometry Problem: Minimize the path to an infinite line parallel to the rectangles Question: What is the competitive ratio? i.e. ratio of found path / shortest path
Lower Bound for the Wall Problem[Papadimitriou, Yannakakis, 1991] Theorem No deterministic algorithm can achieve a competitive ratio of o(n1/2) Proof Place n obstacles of size 1xn into the deterministic path of the player such that the middle of each obstacle Then, the length of the path of the algorithmis n x n/2 = n2/2 There exists a horizontal line which is at most n3/2 steps upwards and hits at most n1/2 rectangles If such a line would not exist then the total area covered by the rectange would be larger than n2 Hence, the offline solution is at most n3/2 This leads to the ratio n1/2
Upper Bounds for the Wall Problem Theorem [Blum, Raghavan, Schieber 1991] The Wall problem can be solved with the sweep algorithm with competitive ratio O(n1/2) Theorem [Fiat, Karloff, Rosen, Berman, Blum, Saks 1996] There is a O(n4/9log n) competitive randomized algorithm for the wall problem.
Deterministic Optimal Solution for the Wall Problem Techniques Move upwards, downwards or right But never to the left Algorithm works in phases Guess distance n by W If something fails we proceed with the next phase at the end Wf = O(n) Use a window to prevent drifting apart In each phase this window size doubles If payable use a full sweep Circumvent a rectangle on the shortest route and switch back to the original height if it costs at most n1/2 indicated by T = W/n1/2 If it is too expensive perform at most n1/2 sweeps in the window A Sweep is a monotone path upwards or downwards (indicated by dir) Use a counter (count) that avoids too many sweeps more than n1/2
The Wall Algorithm dir downwards count 1 W n T n1/2 while wall not reached do (phase starts) walk to the right to the next obstacle O If the distance to the nearest corner of O is at most T then perform full sweep else if O spans the entire window then Go to the nearest corner W 2 W T W/n1/2 count 1 reverse dir else if the corner of O in direction dir is inside the window then go to the corner in direction dir of O else count count+1 reverse dir if count > n1/2 then W 2 W T W/n1/2 count 1 fi fi od T Case 1 Case 2 W Case 3 T T T dir T T dir Case 4
The Wall Algorithm needs O(Wf n1/2) stepswhere Wf is the final window size We bound the number of steps in each phase by c W n1/2 for a constant c Then the over-all number of steps is O(Wf n1/2) Case 1: Each full sweep costs T = W/n1/2 The number of full sweeps is bounded by n This leads to O(W n1/2) steps Case 2: ends a phase without moving, no cost Case 3 and 4: each sweep costs at most n vertical steps The number of sweeps is bounded O(n1/2) by the count mechanism This leads to O(W n1/2) steps T 2nd sweep 1st sweep 3rd sweep
The shortest path has at least length (Wf) We need to prove that the increase of window size is justified Case 2: An obstacle spans the complete window Then the shortest path cannot lie within the window and therefore it is at least W/2 Case 4: The number of sweeps is larger than n1/2 After each sweep we have collected a number of rectangles that obstruct each path by at least T=W/ n1/2 So all paths inside this window have minimum length n1/2 W/ n1/2 = W W T T T
The Competitive Ratio of the Wall Algorithm • The Wall Algorithm needs O(Wf n1/2) steps where Wf is the final window size • The shortest path has at least length (Wf) • The competitive ratio is O(Wf n1/2) = = O(n1/2) (Wf)
The Room Problem Instance: A set of non-overlapping oriented rectangles multiples of the unit size in a d x d - square Starting point in the corner Player is nearsighted Problem: Minimize the path to the middle of the square Observation: shortest path has length of at most d Theorem [Blum, Raghavan, Schieber 1991] The room problem can be solved with competitive ratio of O(n1/2) Theorem Fiat, Bar-Eli, Berman, Yan [94] The room problem can be solved with competitive ratio of O(log n) There is no better algorithm.
s-t-Problem • Instance: • A set of non-overlapping oriented possible unbounded rectangles multiples of the unit size • Starting point s • Target t • Known • coordinates of s and t are known • barriers in distance 1 • Problem: • Minimize the path from s to t • Theorem • There is a O(n1/2) competitive algorithm for the s-t-problem
Thanks for your attentionEnd of 12th lectureNext lecture: Mo 24 Jan 2005, 11.15 am, FU 116Next exercise class: Mo 17 Jan 2005, 1.15 pm, F0.530 or We 19 Jan 2005, 1.00 pm, E2.316