A generic data structure for representing discrete paths on regular - - PowerPoint PPT Presentation

a generic data structure for representing discrete paths
SMART_READER_LITE
LIVE PREVIEW

A generic data structure for representing discrete paths on regular - - PowerPoint PPT Presentation

A generic data structure for representing discrete paths on regular grids e and Alexandre Blondin Mass E. Marcotte LaCIM Universit e du Qu ebec ` a Montr eal June 4th, 2016 GASCom 2016 Blondin Mass e and Marcotte (LaCIM,


slide-1
SLIDE 1

A generic data structure for representing discrete paths on regular grids

Alexandre Blondin Mass´ e and ´

  • E. Marcotte

LaCIM Universit´ e du Qu´ ebec ` a Montr´ eal

June 4th, 2016 GASCom 2016

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 1 / 26

slide-2
SLIDE 2

Discrete paths

(a) (b) (c)

Three discrete paths :

◮ (a) simple; ◮ (b) nonsimple; ◮ (c) closed and simple.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 2 / 26

slide-3
SLIDE 3

Simple paths (self-avoiding walks)

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 3 / 26

slide-4
SLIDE 4

Some questions

Given some discrete path...

◮ ...is it simple? ◮ ...how many intersection points does it have?

Given two discrete regions (closed paths)...

◮ ...what is their intersection? ◮ ...what is their union? ◮ ...what is their difference?

More generally, how efficiently can we answer these questions?

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 4 / 26

slide-5
SLIDE 5

Solution 1: balanced tree/sorting

◮ We walk along the path, step by step; ◮ We insert the points in a balanced tree; ◮ If there is an intersection, it is immediately detected since

the point already belongs to the tree;

◮ Complexity?

◮ O(n log n) time; ◮ O(n) space;

◮ Similarly, it is possible to store all points in a list and

then sort it, yielding the same complexities.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 5 / 26

slide-6
SLIDE 6

Solution 2: boolean matrix

◮ Using a boolean matrix, we can also mark the visited

points;

◮ Let w and h be the width and height of the bounding box

  • f the path;

◮ Then we have the following complexities:

◮ O(n) time; ◮ O(wh) space.

◮ It is of course easy to build examples where w, h ∈ Ω(n), so

that the space complexity is then Θ(n2).

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 6 / 26

slide-7
SLIDE 7

Solution 3: hash table

◮ We mark the visited points with a hash table; ◮ It is well-known that hash tables have O(1) average

complexity per operation;

◮ However, there is no guarantee of having O(1) in the

worst case.

◮ Complexity?

◮ Time : depends on the quality of the hash function; ◮ Space : depends on the capacity of the hash table.

◮ Since the distribution of discrete paths is quite complexe,

it is hard to image a function with guaranteed perfect hashing.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 7 / 26

slide-8
SLIDE 8

Solution 4: linear sorting

◮ In some cases, one can sort in linear time :

◮ Bucket sort; ◮ Counting sort; ◮ Radix sort.

◮ In our case, it suffices to sort the points according to their

x-coordinate and then their y-coordinate (using the radix sort);

◮ Complexity?

◮ Time : Θ(n); ◮ Space : Θ(n).

◮ However, intersection points cannot be detected online.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 8 / 26

slide-9
SLIDE 9

Brlek, Koskas and Proven¸ cal’s data structure

◮ S. Brlek, M. Koskas, X. Proven¸

cal, A linear time and space algorithm for detecting path intersection in Zd, Theoretical Computer Science (TCS) 412, 2011, p. 4841-4850;

◮ The authors introduce a data structure called enriched

radix tree, which allows the detection of self-intersection efficiently.

◮ As a first step, we present it for the N2 grid, then we

discuss how it can be extended to Z2, as well as other grids.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 9 / 26

slide-10
SLIDE 10

The radix relation

◮ The radix relation on N2 is defined by

(x, y) → (x′, y′) if and only if (x, y) =

  • ⌊x′/2⌋, ⌊y′/2⌋
  • ◮ Clearly, → is a strict order relation;

◮ (x, y) is called the parent of (x′, y′); ◮ (x′, y′) is called the child of (x, y); ◮ It may be seen as a 2D generalization of the heap

  • rder for arrays:

1

16

2

14

3

10

4

8

5

7

6

9

7

3

8

2

9

4

10

1

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 10 / 26

slide-11
SLIDE 11

Combining two relations on N2

(a) (b) ◮ (a) The radix (strict) order; ◮ (b) The 4-adjacency relation; ◮ We need to understand how those two relations interact.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 11 / 26

slide-12
SLIDE 12

Observation 1

Lemma (Reformulation of BKP, 2011)

If p, p′ ∈ N2 are neighbors, then exactly one of those two conditions is verified: (i) p and p′ are siblings, i.e. parent (p) = parent (p′); (ii) parent (p) and parent (p′) are neighbors.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 12 / 26

slide-13
SLIDE 13

Observation 2

Lemma (Reformulation of BKP, 2011)

Let p, p′ ∈ Z2 be two nonsibling neighbor points. Then parent (p′) = parent (p) + # » d , where # » d = # » pp′ ∈ {(1, 0), (0, 1), (−1, 0), (0, −1)}.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 13 / 26

slide-14
SLIDE 14

Basic idea

As we travel along the discrete path, we add

◮ a vertex for each new visited point; ◮ undirected edges between some of the neighbor points; ◮ directed edges between some of the points related by the

parent/child relation; Then

  • 1. We start at the origin;
  • 2. We read the next move, which points toward of the four

possible neighbors of the current point;

  • 3. We find this neighbor in the data structure, adding

whatever vertex or edge that is needed;

  • 4. We repeat steps 2-3 as long as the discrete path has not

been completely traveled.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 14 / 26

slide-15
SLIDE 15

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-16
SLIDE 16

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-17
SLIDE 17

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-18
SLIDE 18

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-19
SLIDE 19

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-20
SLIDE 20

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-21
SLIDE 21

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-22
SLIDE 22

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-23
SLIDE 23

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-24
SLIDE 24

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-25
SLIDE 25

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-26
SLIDE 26

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-27
SLIDE 27

Example

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 15 / 26

slide-28
SLIDE 28

Pseudocode (1/3)

1: function DiscretePathGraph(): discrete path graph 2:

u ← Node()

3:

u.point ← (0, 0)

4:

u.parent ← u

5:

u.visited ← true

6:

G.current node ← u

7:

return G

8: end function 9: 10: procedure Move(G : radix tree, d : direction) 11:

next node ← Neighbor(G.current node, d)

12:

⊲ Do something with next node and current node

13:

G.current node ← next node

14: end procedure

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 16 / 26

slide-29
SLIDE 29

Pseudocode (2/3)

1: function Neighbor(u: node, d: direction): node 2:

if u.neighbor[d] is not defined then

3:

p ← u.point

4:

p′ ← p + d

5:

if parent (p) = parent (p′) then

6:

v ← Child(u.parent, d)

7:

else

8:

d′ ← parents direction(p, p′, d)

9:

v ← Child(Neighbor(u.parent, d′), d)

10:

end if

11:

u.neighbor[d] ← v

12:

v.neighbor[−d] ← u

13:

end if

14:

return u.neighbor[d]

15: end function

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 17 / 26

slide-30
SLIDE 30

Pseudocode (3/3)

1: function Child(u : node, d: direction): node 2:

if u.child[i] is not defined then

3:

v ← Node()

4:

i ← child index(d)

5:

v.point ← child coordinates(u.point, d)

6:

u.child[i] ← v

7:

v.parent ← u

8:

v.visited ← false

9:

end if

10:

return u.child[i]

11: end function

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 18 / 26

slide-31
SLIDE 31

The 4-step lemma

Lemma (BKP, 2011)

Let γ be a discrete path of length 4 and pi the i-th point of N2 visited by γ, for 0 ≤ i ≤ 4. Then there exists a least two distinct indices j and j′ such that pj and pj′ are siblings.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 19 / 26

slide-32
SLIDE 32

Complexity

◮ It is proportional to the number of vertices in the graph,

since the number of neighbor edges and parent/child edges is bounded by a constant;

◮ But, points (G) =

  • points (parent i(p))
  • 0 ≤ i ≤ h, p ∈ points (γ)
  • .

where h is the height of the tree.

◮ Therefore, |points (parent i(p))| ≤ 4 5 i |points (p)|

and

|points (G)| =

  • p∈points (γ)

h

  • i=0

|points (parent i(p))| ≤

  • i=0

n 4 5 i = 5n = O(n). ◮ The amortized complexity of Move() is O(n)/n = O(1).

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 20 / 26

slide-33
SLIDE 33

Other grids (1/3)

(a) (b) (c)

◮ (a) 4-regular; ◮ (b) 6-regular; ◮ (c) 8-regular (nonplanar).

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 21 / 26

slide-34
SLIDE 34

Other grids (2/3)

◮ The 4-step lemma does not hold!

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 22 / 26

slide-35
SLIDE 35

Other grids (3/3)

◮ It suffices to modify the radix order:

(x, y) =

  • trunc

x′ + sign(x′) 3

  • , trunc

y′ + sign(y′) 3

  • ,

where trunc(z) = sign(z)⌊|z|⌋ is the truncation of z.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 23 / 26

slide-36
SLIDE 36

A final modification

Lemma (BMM, 2016)

Let p = (x, y), p′ = (x′, y′) ∈ Z2 be two nonsibling neighbor points such that p′ = p + d, where d is any elementary vector on

  • ne of the three grid, and parents direction(p, p′) the vector

satisfying parent (p′) = parent (p) + parents direction(p, p′). Then

parents direction(p, p′) =      (0, y′ − y), if (x + x′) mod 3 = 0; (x′ − x, 0), if (y + y′) mod 3 = 0; (x′ − x, y′ − y),

  • therwise.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 24 / 26

slide-37
SLIDE 37

Other applications

◮ Other operations on discrete regions can be derived

from this algorithm having linear time and space complexity (BTTW, 2014; BMBT, 2016);

◮ For instance, the intersection, the union, the outer

hull, etc.

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 25 / 26

slide-38
SLIDE 38

Concluding remarks

◮ It can be decided in linear time and space whether a

discrete path is simple;

◮ The idea is mostly interesting in theory, since in practice

the performance with other simpler approaches seem comparable;

◮ What other operations can be derived from this data

structure?

◮ What type of grids support this approach (regular,

semi-regular, nonregular, aperiodic, etc.)?

◮ Does there exist a potential function for the data

structure that could be used to prove the amortized complexity O(1) bound for Move()?

Blondin Mass´ e and Marcotte (LaCIM, UQAM) June 4th, 2016 26 / 26