Presentation is loading. Please wait.

Presentation is loading. Please wait.

Point Location Dmitry Rusakov Boris Kronrod. Planar Point Location Lets S be a planar subdivision with n edges. The planar point location problem is.

Similar presentations


Presentation on theme: "Point Location Dmitry Rusakov Boris Kronrod. Planar Point Location Lets S be a planar subdivision with n edges. The planar point location problem is."— Presentation transcript:

1 Point Location Dmitry Rusakov Boris Kronrod

2

3 Planar Point Location Lets S be a planar subdivision with n edges. The planar point location problem is to store S in such a way that we can answer queries of the following type: Given a query point q, report a face f of S that contains q. If q lies on an edge or coincides with a vertex, the query algorithm, should return this information.

4 Algorithm requirements There’re situations, like interactive geographic information system, where system must respond very fast to each query. So we need fast algorithm. In the same time, the complexity of data structure, that algorithm is using, must be small since typical geographic information system includes a large number of regions.

5 Naive Approach Hold a list of faces, for each face hold a list of border edges of this face. For query point q find a face that includes q, by checking faces one by one. Space complexity: O(n) Time complexity: O(n), because each edge is checked maximum twice.

6 Naive Approach - Analysis O(n) time complexity is too big for real applications. Source of the problem - checking against all faces. In hope to achieve O(log n) time, we must sort faces in some way, which is impossible with complex faces. Solution - work with simple space subdivisions.

7 Refinement Subdivision S` is refinement of subdivision S if every face of S` lies completely in one face of S. Once we know the face f` of S` containing q, we know the face f of S containing q as well.

8 Partition into Slabs Partition the plane into vertical slabs, by drawing vertical lines through all vertices of the given subdivision S. For query point q, find a slab it belongs to and find a corresponding face in this slab.

9 Partition into Slabs, Example

10 Slab properties Within a slab, there’re no vertices of S. All edges intersecting a slab completely cross it and they don’t cross each other.

11 Data Structure Slabs sorted by x coordinate. n slabs are stored in binary tree allowing O(log n) search time. In each slab we sort an edges intersecting it according to above-below relationship. n edges intersecting the slab are stored in binary tree allowing O(log n) search time. Worst case: O(n 2 ) storage complexity.

12 O(n 2 ) storage case n/4 slabs

13 Query Find a slab containing q. O(log n) time. Find an edge immediately above(below) q in found slab. O(log n) time. Each edge uniquely defines a face below(above) it. Time complexity: O(log n) Storage requirements: O(n 2 ) - BAD!!!

14 Search for A Better Refinement We want to find another refinement, that will allow fast point location queries but still has a complexity of original subdivision S. Indeed such a refinement exists and it’s called trapezoidal map.

15 Simplifications Lets get rid of the unbounded trapezoid- like faces that occur at the boundary of the scene. This can be done by introducing a large axis-parallel rectangle R that contains the whole scene. Lets assume that all segments are in general position, i.e. no two distinct endpoints have the same x-coordinate.

16 Trapezoidal Maps The trapezoidal map T(S) of S - also known as vertical decomposition or trapezoidal decomposition of S - is subdivision obtained by drawing two vertical extensions from every endpoint p of a segment in S, one extension going upwards and one going downwards. The extensions stop when they meet another segment of S or the boundary of R.

17 Trapezoidal Maps, Example

18 Partition into Slabs vs. Trapezoidal Map

19 Trapezoid Maps - Properties Lemma 1 : Each face in a trapezoidal map of a set S of line segments in general position has one or two vertical sides and exactly two non-vertical sides.

20 Proof of Lemma 6.1 Let f be a face in T(S). We first prove that f is convex. Any corner of f is either an endpoint or a point where the vertical extension abuts a segment(or an edge of R) or a corner of R. Due to vertical extensions, any corner of f has an interior angle less or equal of 180 o.

21 Proof of Lemma 1(cont.) The convexity of f implies that it can have at most two vertical sides f cannot have more that two non-vertical sides, because otherwise they will meet in edge point and thus will be separated by vertical line through this point. f is bounded, thus it has exactly two non- vertical sides and at least one vertical side.

22 Notations Let top(D) (bottom(D)) be the segment of S, or edge of R, bounding the trapezoid D from above (below). Let denote the endpoint defining the left(right) edge by leftp(D) (rightp(D)). Notice that D is uniquely determined by top(D), bottom(D), leftp(D) and rightp(D).

23 Notations, Examples D rightp(D) leftp(D) top(D) bottom(D) top(D) D rightp(D) bottom(D) leftp(D)

24 Trapezoidal Maps, Complexity Lemma 2: The trapezoidal map T(S) of a set of n line segments in general position contains at most 6n+4 vertices and at most 3n+1 trapezoids.

25 Proof of Lemma 2 A vertex of T(S) is either a vertex of R, an endpoint of a segment in S, or else the point where the vertical extension starting at endpoint abuts on another segment or at boundary of R. Thus the total number of vertices in T(S) is bounded by: 4+2n+2(2n) = 6n+4

26 Proof of Lemma 2 (cont.) Each trapezoid, D, has a point leftp(D). Lets count the possible number of leftp(). In the case of ambiguity consider leftp(D) as a point of bottom(D) or top(D) segments whenever possible.

27 Four cases for leftp(D) D D D D Endpoint and corresponding segment is marked in cyan.

28 Non-trivial case In case of leftp(D) lying on both top(D) and bottom(D), consider leftp(D) as an endpoint of bottom(D). leftp()

29 Proof of Lemma 2 (cont.) Thus right endpoint of any segment can be leftp() of only one trapezoid, and left endpoint of any segment can be leftp() of maximum two trapezoids. The lower left corner of R is a leftp() of exactly one trapezoid. It follows that the total number of trapezoids is bounded by 3n+1.

30 Adjacent Trapezoids We call two trapezoids D, D` adjacent if they meet along a vertical edge. For set of points in general position a trapezoid has at most four adjacent trapezoids. D D1D1 D2D2 D3D3 D4D4 D5D5

31 Trapezoidal Map, Representation We use a specialized structure that uses the adjacency of trapezoids to link the subdivision as a whole. The structure contains records for trapezoids in T(S). The record for trapezoid D stores pointers to top(D),bottom(D),leftp(D),rightp(D) and pointers to its at most four neighbors.

32 A Randomized Incremental Alg. In this section we will develop a randomized incremental algorithm that constructs the trapezoidal map T(S). During the construction the algorithm also builds a data structure D that can be used to perform point location queries in T(S). This is not a sweep line algorithm, because it doesn’t builds the data structure for queries

33 Desired Data Structure Directed acyclic graph with a single root Exactly one leaf for every trapezoid in trapezoid map of S Every inner node have out-degree 2 2 types of inner nodes: –x-nodes are labeled with an end-point of some segment in S –y-nodes are labeled by segment itself

34 Example The trapezoidal map of two segments an its’ search structure p1p1 p1p1 A C F D B EG q1q1 q2q2 p2p2 s1s1 s2s2 A s1s1 q1q1 q2q2 p2p2 s2s2 CBDEFG s2s2

35 Algorithm TrapezoidalMap (S) Input: A set S of n non-crossing line segments Output: The trapezoidal map T(S) and a search structure D for T(S) in a bounding box 1. Determine a bounding box R that contains all segments of S, and initialize the trapezoidal map T and search structure D for it 2. Compute a random permutation s 1,s 2,…,s n of the elements of S …

36 Alg. TrapezoidalMap (S) (cont...) 3. for i <-- 1 to n 4. do Find the set  0,  ,…,  k of trapezoids in T properly intersected by s i 5. Remove  0,  1,…,  k from T and replace them by the new trapezoids that appear because of the intersection of s i 6. Remove the leaves for  0,  1,…,  k from D, and create leaves for the new trapezoids. Link the new leaves to the existing inner nodes by adding some new inner nodes as explained below.

37 Detailed description of Alg. Let Si be the set {s 0,s 1,…,s i } The loop in Alg. invariant is that T is a trapezoidal map for S i and D is valid search structure for T T is initialized as T(S 0 ) = T(empty) and D contains only range box R a leaf. For each new segment s i+1 we can find  0 by running point location query for p i+1 on T(S i ) using by  i

38 Example 00 11 33 22 p q s

39 Alg. FollowSegment (T,s i ) Input: A trapezoidal map T, and a new segment s i. Output: The sequence  0,  1,…,  k of trapezoids intersected by s i. 1. Let p and q be a left and right endpoints of s i. 2. Search with p in the search structure to find  0. 3. j <-- 0 …

40 Alg. FollowSegment (T,s i ) (cont...) … 4. while q lies to the right of rightp(  j ) 5. do if rightp(  j ) lies above s i 6. then Let  j+1 be the lower right neighbor of  j 7. else Let  j+1 be the upper right neighbor of  j 8. j <-- j + 1 9. return  0,  1,…,  j

41 Updating T and D Let’s start with simple case that s i is completely contained in trapezoid  =  0

42 Simple case (1) T(S i-1 )  pipi qiqi sisi D(S i-1 ) 

43 Simple case (2) T(Si)T(Si) C D(Si)D(Si) pipi A sisi qiqi BC D A B D

44 General case (1) 00 11 22 33 pipi ii sisi T(S i-1 )

45 General case (2) B C D E pipi F sisi T(Si)T(Si) A

46 General case (3) D(S i-1 )  11 22 33

47 General case (4) D(Si)D(Si) A sisi qiqi CBDEF sisi sisi sisi

48 Theorem 3 Algorithm TrapezoidalMap computes the trapezoidal map T(S) of set S of n line segments in general position and a search structure D for T(S) in O(n log(n)) expected time. The expected size of the search structure is O(n) and for query point q the expected query time is O(log(n))

49 Proof of theorem 3 (1) 3 parts in this theorem will be proved –expected time of T(S) and D for T(S) building –expected size of D –expected time of query for given query point q Proof using by backward analysis

50 Proof of theorem 3 (2) Let’s start with the query time of search structure D for a fixed query point q. The query time is equal to the length of the search path for q in D. Thus it’s necessary to bound the length of search path. As we already observed every step in TrapezoidalMap algorithm adds maximum 3 levels into D structure. Hence, 3n is the upper bound on the query time for q.

51 Proof of theorem 3 (3) We are interested in an expected time as well as not in worst cases. Let X i, for 1<=i<=n, denote the number of nodes on the query path created in iteration i. Since we consider S and q to be fixed, X i is a random variable - it depends on the order of segments only. The expected path length is n n E[  X i ] =  E[X i ] i=1 i=1

52 Proof of theorem 3 (4) We already saw that in any iteration alg. adds at most 3 nodes on the search path, so X i <= 3. Let’s P i denotes the probability that there exists the node on a search path of q that is created in iteration i E[X i ] <= 3P i

53 Proof of theorem 3 (5) Iteration i contributes a node to a search path of q exactly if  q (S i-1 ), the trapezoid containing q in T(S i-1 ), is no the same as  q (S i ) Pi = Pr[  q (S i-1 ) not the same as  q (S i )] If  q (s i-1 ) not the same as  q (s i ), then  q (s i ) must be one of the trapezoids created in iteration i. Note that all trapezoids created in iteration I are adjacent to s i : either top(  ) or bottom(  ) is s i, or leftp(  ) or rightp(  ) as an endpoint of s i

54 Proof of theorem 3 (6) Backward analysis: consider a fixed set S i as a subset of S. The T(S i ) and  q (s i ) defined as function of S and does not depend on the order in which segments of S i were inserted. Let’s compute the probability that  q (s i ) disappear as a result of removing a random segment s i from the S i. It disappears iff s i is either top(  ) or bottom(  ) is s i, or leftp(  ) or rightp(  ) as an endpoint of s i

55 Proof of theorem 3 (7) The probability that top(  ) or bottom(  ) is s i, is at most 1/i for each case. leftp(  ) disappears only if si is the only segment in S i with leftp(  ) as endpoint. Hence the probability that leftp(  ) disappears is at most 1/i as well. Hence we can conclude that: Pi=Pr[  q (S i-1 ) not the same as  q (S i )] = Pr[  q (S i ) not belong to  (S i-1 ) ] <= 4/i

56 Proof of theorem 3 (8) Putting it all together we get the bound on the expected query time: n n n n E[  X i ]<=  3P i <=  12/i=12  1/i=12H n i=1 i=1 i=1 i=1 H n =1/2+1/3+1/4+…+1/n ln(n) < H n < ln(n) + 1

57 Proof of theorem 3 (9) Now we will compute the bound size of D. Each leaf in D corresponding one to one with trapezoid in T(S), of which there are O(n) (see Lemma 2) The total number of nodes in D is bounded by n O(n)+  ( number of inner nodes created by iter. i) i=1 Let k i be a number of trapezoids created in iter. i. The number of inner nodes created in the same iter. is k i - 1. Hence: n n O(n)+E[  ( k i -1)] = O(n)+E[  k i ] i=1 i=1

58 Proof of theorem 3 (10) Consider a fixed set S i as a subset of S. for a trapezoid  and segment s from S i let: 1 if  disappears from T(S i ) when s i is removed from S i  ( ,s) := { 0 otherwise In the analysis of the query time we observed that here are at most 4 segments that cause a given trapezoid to disappear  d( ,s) <= 4|T(S i )| = O(i) s in Si  in T(Si) Now, k i is the number of trapezoids created by insertion of s i, or, equivalently the number of trapezoids in T(S i ) that disappears when s i removed.

59 Proof of theorem 3 (11) Since si is a random element in S i we can find the expected value of K i by the taking average over all s in S i : E[k i ]=1/i*  d( ,s)<= O(i)/i = O(1) s in Si  in T(Si) We conclude that expected number of new inner nodes created in each iteration is O(1), from which O(n) bound on the expected size of D.

60 Proof of theorem 3 (12) To bound the expected running time of Alg. we only need to observe that the time to insert segment s i is O(k i ) plus the time needed to locate the left endpoint of s i in T(S i -1). Thus the time bound is : n O(1) +  {O(logn) + O(E[k i ])} = O(nlogn) i=1

61 Dealing with degenerate cases Symbolic shear transformation  (x, y) = (x +  y,  y) Given a set S of n arbittrary non-crossing line-segments, we will run algorithm TrapezoidalMap on the set  S := {  s : s from S }.

62 Dealing with degenerate cases To reduce probability of numerical problems in transformation every point  (p) = (x +  y,  y) will simply be stored as (x,y). We only need to make sure that the Alg. treats this data correctly. 2 types of elementary operation on input points

63 Dealing with degenerate cases kThe first operation tkes 2 distinct points p and q and desides whether q lies to the left, to the right, or on the vertical line throught p. kThe second oeration takes one of the input segments and tests wheter q lies above, below or on this segment.

64 Tail Estimate In previous theorem it was proved that expected query time is O(log n). This is a rather weak result. In fact, there’s no reason to expect that maximum query time of the search structure is small. In this sections we shall prove that probability that search structure has a bad query time for some query point is very small.

65 Lemma 6 Let S be a set of n non-crossing line segments, let q be a query point, and let a be a parameter with a > 0. Then the probability that the search path for q in the search structure computed by Algorithm TrapezoidalMap has more than 3 a ln(n+1) nodes is at most 1/(n+1) a ln 1.25 - 1.

66 Proof of Lemma 6 (1) We would like to define random variables X i, with 1 <= i <= n, such that X i = 1 if at least one node on the search path for q has been created on iteration i. Unfortunately, the random variables created this way are not independent. We didn’t need independence in the Proof of Theorem 3, but we shall need it here. Lets use a little trick!

67 Proof of Lemma 6 (2) We define a directed acyclic graph G, with one source and one sink. Paths from source to sink correspond to permutations in S. There’s a node for every subset of S, including one for the empty set. A subset S` of cardinality i has outgoing edge to the subset S`` of cardinality i+1, if S`` contains S` and edge is associated with segment S``\S`.

68 Permutation Graph It is convenient to imagine the nodes as being grouped into n+1 layers, such that layer i contains the subsets of cardinality i. {1,2,3,4} {1,2,3} {2,3,4} {} {1}{4} {1,2}{3,4} 14 2 3 4 3 2 1

69 Proof of Lemma 6 (3) Directed paths from the source to the sink in G now correspond one-to-one to permutations of S, which correspond to possible executions of algorithm TrapezoidalMap. Lets mark the edge if this insertion changes the trapezoid containing point q. By backward analysis we get that any node in G has at most four marked incoming edges. If a node has less than four marked edges, mark more edges arbitrary, to total 4 marked.

70 Proof of Lemma 6 (4) Lets define an indicator X i, X i =1 iff the i- th edge on the sink-to-source path in G is marked. Since each node in layer i has i incoming edges, exactly four of which are marked (assuming i>3), this implies that Pr[X i =1]=4/i for i>3, and Pr[X i =1]=1 for i<=3. Note that X i are independent.

71 Proof of Lemma 6 (5) Let Y = sum Xi. The number of nodes in the search path for q is at most 3Y. Lets bound the probability that Y exceeds a ln(n+1). We use Markov’s inequality: For any non-negative random variable Z and any a > 0

72 Proof of Lemma 6 (6) So for any t > 0 we have Recall that expected value of the sum of random variables is the sum of the expected values and for independent random variables expected product is the product of expected values, so we have:

73 Proof of Lemma 6 (7) and if we choose t = ln 1.25, we get and we have:

74 Proof of Lemma 6 (8) Putting everything together, we get the bound we want to prove:

75 Lemma 7 Let S be the set of n non-crossing line segments, and let a be a parameter a > 0. Then the probability that the depth of the search structure computed by Algorithm TrapezoidalMap for S is more than 3 a ln(n+1) is at most 2/(n+1) (a ln1.25-3).

76 Proof of Lemma 7 We will call two query points q and q` equivalent if they follow the same path through the search structure D. Recall partition the plane into vertical slabs. This defines a decomposition of the plane into at most 2(n+1) 2 trapezoids Any two points lying in the same trapezoid in this decomposition must be equivalent in every possible structure for S.

77 Proof of Lemma 7 (cont.) Thus the depth of D is the maximum of the length of the search path for at most 2(n+1) 2 query points. By Lemma 6 the probability that length of search path for fixed point q exceeds 3 a ln(n+1) is at most 1/(n+1) (a ln 1.25 -1) Thus the probability that length of the search path for any one of 2(n+1) 2 test points exceeds the bound is therefore at most: 2(n+1) 2 /(n+1) (a ln 1.25 - 1) = 2/(n+1) (a ln 1.25 -3)

78 Discussion of proved results Lemma 7 implies that expected maximum query time is O(log n). Take a = 20, then a probability that the depth of D is more than 3 a ln(n+1) is at most 2/(n+1) 1.4 which is less than 1/4 for n>4. Similarly, the size of D is O(n) and construction time is O(n log n) with probability at lest 3/4.

79 Main result Theorem 8: Let S be a planar subdivision with n edges. There exists a point location data structure for S that uses O(n) storage and has O(log n) query time in the worst case. The structure can be build in O(n log n) expected time.

80 The Algorithm Run algorithm TrapezoidalMap on the set S, keeping track of the search structure that is being created. As soon as size exceeds c1*n or depth exceeds c2*log n for suitably chosen constants c1 and c2, stop the algorithm and start it with another permutation. Since the probability of good permutation is 1/4 (a=20) so we expect to finish in 4 trials.

81 Summary We learned an algorithm for point location problem. An algorithm in O(n log n) expected time creates a search structure of size O(n), which is capable to answer point location queries in O(log n) time.

82 The End

83 Another approach -persistency Recall the slabs subdivision. The problem is that we hold a tree for each slab, so we get O(n 2 ) space. But the structure of trees in the adjacent slabs are almost identical. Idea: Do not hold the new trees, but only the changes of the previous(from left to right) Result: O(n) space,with same O(log n) time.


Download ppt "Point Location Dmitry Rusakov Boris Kronrod. Planar Point Location Lets S be a planar subdivision with n edges. The planar point location problem is."

Similar presentations


Ads by Google