Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann...

36
Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg
  • date post

    15-Jan-2016
  • Category

    Documents

  • view

    219
  • download

    0

Transcript of Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann...

Page 1: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Klee’s Measure Problem

Computational Geometry, WS 2007/08Group Work

Prof. Dr. Thomas OttmannKhaireel A. Mohamed

Algorithmen & Datenstrukturen, Institut für InformatikFakultät für Angewandte WissenschaftenAlbert-Ludwigs-Universität Freiburg

Page 2: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 2

Overview

• The measure problem

• 1D analysis

• 2D analysis

• Naïve solution

• Implicit area computation by segment tree

• Improved solution

Page 3: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 3

The Measure Problem

• Victor Klee, 1977• Given a set of n horizontal line-segments, compute the length of

their union on the real line.

Page 4: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 4

1D Problem (Original)

• Sorting and partitioning– Total partitions (space):

– Time:

• Sweep direction: Left to right– Event Q:

– Status-measure T:

Page 5: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 5

1D Problem (Original)

• Time complexities– Time per event:

– Total sweep time:

– Total runtime:

Page 6: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 6

The Measure Problem in 2D

• Jon Bentley, 1977• Given a set of n rectangles on the 2D plane, compute the area of

their union.

Page 7: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 7

(xhi, yhi)

Representing a Rectangle

(xlo, ylo)

r

xlo xhi

ylo

yhi

• Assume that all rectangles in the set are non-trivial• Sufficient to store bottom-left and top-right coordinates

Page 8: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 8

2D Problem – Sweepline Approach

epi epi+1Sweep direction

Page 9: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 9

2D Problem – Sweepline Approach

• Sorting and partitioning– Total partitions (space):

– Time:

• Sweep direction: Left to right– Event Q:

– Status-structure T:

epi

Page 10: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 10

2D Sweepline – Naïve Solution

• Let m(i) be the 1D measure of the active vertical segments at epi.

• Then the measure for the 2D slab between epi and epi+1:

• In general, for k 2D slabs, the measure for the entire set of rectangles:

epi epi+1

Page 11: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 11

Analyses – 2D Naïve

• Maintaining the status-structure T, per event point epi

– Time (per insertion):

– Time (per deletion):

– Time to compute m(i):

• Total insertions (into T) = Total deletions (from T) =

• Overall performance of the naïve algorithm– Time complexity:

Page 12: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 12

Analyses – Naïve Worst Case

• Worst case runtime:

• Can this be avoided?

Page 13: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 13

Improving the Naïve Approach

• Main reason for inefficiency:

• Overcoming the inefficiency:– Limit the amount of work done at epi by

Page 14: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 14

Observation for Improvement

• Consider the slab between epi and epi+1 when a new rectangle q becomes active.

q

epi epi+1

q

epi epi+1

q

epi epi+1

q

epi epi+1

Page 15: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 15

Decomposing the Vertical Sweep

Idea:• All segments appearing on the vertical sweepline can be composed

of a collection of consecutive fragments [vj, vj+1].

• A single offline structure is sufficient to represent the vertical sweeps to collectively compute the measure m(i) at each epi.

• Insertions and deletions of segments affect the structure only by changing the augmented values in the internal nodes.

• At the start of the event point epi, the measure for the previous segment m(i-1) can be read off the root immediately.

Page 16: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 16

The Segment Tree as Status-Structure

• The ordered (vertical) segments are entered as leaves in a balanced binary search tree .

• Each vj (except v1 and vm) will occur twice, representing the closed non-overlapping segment [vj, vj+1].

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

v1

vm

1

3

3

5

5

6

6

8

8

9

Page 17: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 17

Keeping Track of Segments

• The segment tree represents all O(n) partitions on the vertical axis.

• When a rectangle becomes active (or inactive), we mark the internal nodes in accordingly; i.e. we should be able to know– if the subtree under a node x in fully or partially covers a set of

intervals – and thus, the measure at node x, and

– the number of segments that fully covers the range of x.

vi

vj

vj

vk

vi

vj

vj

vk

x x

x’

Page 18: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 18

Implicit Handling

• It is NOT necessary to mark all the individual fragments from which a segment q is composed. Why?

Page 19: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 19

Classifying Nodes based on a Segment q

• Given a segment q = [vi, vj], then a node in is said to be

– q-full if it covers a segment fully contained in q

– q-partial if it is not q-full but has a child that is either q-partial or q-full

• Consider the search paths for ‘[vi’ and ‘vj]’; let the node where the two paths diverge be t.– All nodes encountered before t must have been

v1

vm

[vi

vj]t

q

Page 20: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 20

1-Umbrella of the Segment q

• The 1-umbrella of a segment q is the subtree of rooted at t consisting of– all the q-partial nodes on the hi-line from t to hi-tip,

– all the q-partial nodes on the lo-line from t to lo-tip, and

– all the q-full nodes which are directly connected to the hi-line or lo-line.

[vi

vj]

tq

hi-tip

lo-tip

hi-line

lo-line

Page 21: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 21

1-Umbrella of the Segment q

Lemma:• The 1-umbrella of the segment q can be built in O(log n) steps.

Page 22: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 22

Marking Nodes on the 1-Umbrella

• We maintain the following information in for any sets of segments, where augment in the node x– x.val : The measure of the fragments in the subtree of x which are

covered by 1-umbrellas through it or below it

– x.cnt : A count of the number of times in which x becomes a q-full node of some umbrella.

vi

vj

vj

vk

vm

t

Page 23: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 23

Inserting a Segment q into

• Input: – The root of the segment tree

– The range q = [vi, vj]

• Output: – The measure of the vertical line-segments at root.val

• Idea:– Percolating measure differences between successive levels in

• Determine the 1-umbrella for q.• Handle measure differences from lo-tip to t.• Handle measure differences from hi-tip to t.• Combine measure differences and percolate to root.

Page 24: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 24

Example – Activate qA

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]

[5,6]v = 0c = 0

[3,5]v = 0c = 0

[1,3]

[1,5]v = 0c = 0

[6,9]

[5,9]v = 0c = 0

[1,9]v = 0c = 0

Sweep direction

qA

Page 25: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 25

Example – Activate qB

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qB

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 0c = 0

[5,6]v = 1c = 1

[3,5]v = 2c = 1

[1,3]

[1,5]v = 2c = 0

[6,9]v = 0c = 0

[5,9]v = 1c = 0

[1,9]v = 3c = 0

Page 26: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 26

Example – Activate qC

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qC

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 2c = 1

[5,6]v = 1c = 2

[3,5]v = 2c = 1

[1,3]

[1,5]v = 2c = 0

[6,9]v = 2c = 0

[5,9]v = 3c = 0

[1,9]v = 5c = 0

Page 27: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 27

Special Cases

• When t equals lo-tip, then t also equals hi-tip. Why?

• The percolated measure difference have to be ‘killed’ if x.parent.cnt ≥ 1. Why?

Page 28: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 28

Inserting a Segment

Lemma:• Inserting a segment and maintaining the information in requires

O(log n) time.

Page 29: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 29

Deleting a Segment

Lemma:• Deleting a segment and maintaining the information in requires

O(log n) time.

Page 30: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 30

Example – Deactivate qA

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qA

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 2c = 1

[5,6]v = 1c = 2

[3,5]v = 2c = 1

[1,3]

[1,5]v = 2c = 0

[6,9]v = 2c = 0

[5,9]v = 3c = 0

[1,9]v = 8c = 1

Page 31: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 31

Example – Deactivate qC

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qC

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 2c = 1

[5,6]v = 1c = 1

[3,5]v = 0c = 0

[1,3]

[1,5]v = 0c = 0

[6,9]v = 2c = 0

[5,9]v = 3c = 0

[1,9]v = 8c = 1

Page 32: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 32

Example – Activate qD, qE

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qD

qE

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 2c = 1

[5,6]v = 1c = 1

[3,5]v = 0c = 0

[1,3]v = 0c = 0

[1,5]v = 0c = 0

[6,9]v = 2c = 0

[5,9]v = 3c = 0

[1,9]v = 3c = 0

Page 33: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 33

Example – Deactivate qD

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qD1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 2c = 2

[5,6]v = 1c = 1

[3,5]v = 0c = 0

[1,3]v = 2c = 1

[1,5]v = 2c = 0

[6,9]v = 2c = 0

[5,9]v = 3c = 0

[1,9]v = 5c = 0

Page 34: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 34

Example – Deactivate qE, qB

0

1

2

3

4

5

6

7

8

9

1 2 3 4 5 6 7 8 9 10

0

A

B

C

D

E

Sweep direction

qE

1

3

3

5

5

6

6

8

8

9[8,9]

[6,8]v = 2c = 2

[5,6]v = 1c = 1

[3,5]v = 0c = 0

[1,3]v = 2c = 0

[1,5]v = 0c = 0

[6,9]v = 2c = 0

[5,9]v = 3c = 0

[1,9]v = 3c = 0

Page 35: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Computational Geometry, WS 2007/08Prof. Dr. Thomas Ottmann 35

The Improved Solution

Theorem:• The measure problem for a set of n rectangles in the plane can be

solved on O(n log n) time.

Page 36: Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.