Upload
jania
View
22
Download
0
Embed Size (px)
DESCRIPTION
Search Algorithms Winter Semester 2004/2005 17 Jan 2005 12th Lecture. Christian Schindelhauer [email protected]. Spatial Searching. Prolog: Searching with some help Searching with total Uncertainty Nearsighted Search The Cow Path Problem The Concept of Competitive Analysis - PowerPoint PPT Presentation
Citation preview
1
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Search AlgorithmsWinter Semester 2004/2005
17 Jan 200512th Lecture
Christian Schindelhauer
Search Algorithms, WS 2004/05 2
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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
Search Algorithms, WS 2004/05 3
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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
???
Search Algorithms, WS 2004/05 4
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Competitive Analysis
How to evaluate the online solutionClassical 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
=
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“
benötigt.
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
Search Algorithms, WS 2004/05 5
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Solution of the Cow Fence Problem
Deterministic Cow-Path
1. dir left
2. for i 0 to log n do
3. go 2i steps to direction dir
4. go 2i steps back to the origin
5. revert direction dir
6. od
Theorem [Baeza-Yates, Culberson, Rawlins, 1993]
The deterministic Cow-Path algorithm has a competitive ratio of 9.
This competitive ratio is optimal.
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
Search Algorithms, WS 2004/05 6
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Exit
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’2d’d’
2d’d’+1
d’/2d’/4 ...
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
Search Algorithms, WS 2004/05 7
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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
?
Search Algorithms, WS 2004/05 8
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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...
1
k2
Search Algorithms, WS 2004/05 9
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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.
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (LZW)“
benötigt.
Search Algorithms, WS 2004/05 10
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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 pathVariants1. Variant: the distance n is known:
Then a (2m-1) competitive (deterministic) algorithm optimally solves the case
2. 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:
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (LZW)“
benötigt.
Search Algorithms, WS 2004/05 11
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
Spiral Search Cow
Spiral-Search-Cow1. i 02. while bull not found do3. i i+14.
5. explore f(i) steps of ray (i mod m)+16. return to the starting point7. od
TheoremThe spiral search cow algorithm has a competitive ratio of
Proof:Worst case: bull in depth f(i)+1
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (LZW)“
benötigt.
Search Algorithms, WS 2004/05 12
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
The spiral search cow algorithm has a competitive ratio of
TheoremProof:Worst case: bull in depth f(i)+1Steps of spiral-search-cow:
Competitive ratio:
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (LZW)“
benötigt.
Search Algorithms, WS 2004/05 13
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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 ratioPerform 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
Search Algorithms, WS 2004/05 14
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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
=Zur Anzeige wird der QuickTime™
Dekompressor „TIFF (Unkomprimiert)“ benötigt.
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
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
Search Algorithms, WS 2004/05 15
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Why Randomness Helps
-1:1=
13:1=
34:2=
28:2=
49:3=
310:4=
2.511:5=
2.219:3=6.3..
20:4=5
21:6=3.5
22:7=3.1..
23:8=2.8.. ...
42:6=7
43:7=6.1..
11:5=2.2
• Expected probabilistic competitive ratio: 6• Optimal deterministic ratio: 9
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
Search Algorithms, WS 2004/05 16
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Smart Cow [Kao, Reif, Tate]
5. repeat
6. Explore path (p) up to distance d
7. d d r
8. p p mod m +1
9. 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..
Search Algorithms, WS 2004/05 17
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Probabilism versus Determinism
mRandomized
Competitive Ratio of Smart-Cow
Optimal Deterministic Ratio of Spiral-
Search-Cow
2 4.59112... 9
3 7.73232... 14.5
4 10.84181... 19.96296...
5 13.94159... 25.41406...
6 17.03709... 30.85984...
7 20.13033... 36.30277...
Search Algorithms, WS 2004/05 18
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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 geometryProblem:
– 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
Search Algorithms, WS 2004/05 19
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Lower Bound for the Wall Problem[Papadimitriou, Yannakakis, 1991]
TheoremNo 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
Search Algorithms, WS 2004/05 20
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Upper Bounds for the Wall Problem
Theorem [Blum, Raghavan, Schieber 1991]The Wall problem can be solved with thesweep 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.
Search Algorithms, WS 2004/05 21
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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
Search Algorithms, WS 2004/05 22
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Case 4
Case 3
Case 2
The Wall Algorithm
1. dir downwards2. count 13. W n4. T n1/2
5. while wall not reached do (phase starts) 6. walk to the right to the next obstacle O7. If the distance to the nearest corner of O
is at most T then8. perform full sweep9. else if O spans the entire window then10. Go to the nearest corner11. W 2 W12. T W/n1/2
13. count 114. reverse dir15. else if the corner of O in direction dir is inside
the window then16. go to the corner in direction dir of O
else17. count count+118. reverse dir19. if count > n1/2 then20. W 2 W21. T W/n1/2 22. count 123. fi24. fi25. od
Case 1
T
T
W
dir
T
T
dirT
T
Search Algorithms, WS 2004/05 23
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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) stepsCase 2:
– ends a phase without moving, no costCase 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
1st sweep
2nd sweep
3rd sweep
Search Algorithms, WS 2004/05 24
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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
T
W
T
T
Search Algorithms, WS 2004/05 25
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.
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
=Zur Anzeige wird der QuickTime™
Dekompressor „TIFF (Unkomprimiert)“ benötigt.
O(Wf n1/2)
(Wf)
= O(n1/2)
Search Algorithms, WS 2004/05 26
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
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.
Search Algorithms, WS 2004/05 27
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
s-t-Problem
Instance:
–A set of non-overlapping oriented possible unbounded rectangles multiples of the unit size
–Starting point s
–Target tKnown
–coordinates of s and t are known
–barriers in distance 1 Problem:
–Minimize the path from s to tTheorem
–There is a O(n1/2) competitive algorithm for the s-t-problem
28
HEINZ NIXDORF INSTITUTEUniversity of Paderborn
Algorithms and ComplexityChristian Schindelhauer
Thanks for your attentionEnd of 12th lecture
Next 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