38
06/16/22 Navigation in Object Grap hs 1 Navigation in Object Graphs Mitch Wand and Karl Lieberherr

Navigation in Object Graphs

Embed Size (px)

DESCRIPTION

Navigation in Object Graphs. Mitch Wand and Karl Lieberherr. Searching for Reachable Objects. Task: Given an object o1 of class c1 in an object graph, find all objects of type c2 that are reachable from o1. - PowerPoint PPT Presentation

Citation preview

Page 1: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 1

Navigation in Object Graphs

Mitch Wand

and

Karl Lieberherr

Page 2: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 2

Searching for Reachable Objects

• Task: Given an object o1 of class c1 in an object graph, find all objects of type c2 that are reachable from o1.

• Assumptions: we know the class structure that describes the object graph, but we know nothing else about the object graph except the class of the current object.

Page 3: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 3

c2c1

Classes and Objects: Basic Notationse

c2c1

Class c1 has a part e of type c2

Class c1 inherits from class c2

c1o1:c1 Object o1 is of class c1

c1o1:c1 c2 Object o1 is of type c2 (i.e., its class is a subclass of c2)

o2:o1:e

Object o1 has a part e which is object o2

Page 4: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 4

Finding the first step for the search

C1

o1:C1

C2

o2:

o3:

o4:

Which arrows might lead to an object of type C2?

ObjectGraph-object

Traversal Strategy:from C1 to C2

Page 5: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 5

C2C1e

C2C1

e(C1,C2)

C1 <= C2

C1o1:C1 Class(o1) = C1

C1o1:C1 C2 Object o1 is of type C2:Class(o1) <= C2

Relations between Classes

C2C1 C(C1,C2) (that is, e(C1,C2) for some e)

Page 6: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 6

o2:o1:e

e(o1,o2)

Relations between Objects

o2:o1: O(o1,o2) (that is, e(o1,o2) for some e)

Page 7: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 7

Operations on Relations

• R.S = {(x,z) | exists y s.t. R(x,y) and S(y,z)}

• R* = reflexive, transitive closure of R

Page 8: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 8

Possible edges in the object graph

o1:

C1

e

o2:

C2

e

e(o1, o2) implies class(o1) (<= .e .=> ) class(o2) in the class graph

“up, over, and down”

O(o1, o2) implies class(o1) (<= .C .=> ) class(o2) in the class graph

Page 9: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 9

Which edges to follow to C2?

C1

o1:C1

From o1 of class C1, follow edge e iff there is some object graph O and some o2, o3 s.t.

(1) e(o1,o2), (2) O*(o2,o3), and (3) class(o3) <= C2

o2:e*

o3:

C2

The existential quantifier “there is some object graph” represents our lack of knowledge about the rest of the object graph

Page 10: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 10

Example

Basket Fruit

Vegetable Apple

Orange

f

v

from Basket to Orange

b1:Basket a1:Apple

v1:Vegetable

v

f

class graph

object graphb1:Basket

f

object graphslice

prematuretermination

Page 11: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 11

Example

Basket Fruit

Vegetable Apple

Orange

f

v

from Basket to Orange

b1:Basket a1:Orange

v1:Vegetable

v

f

class graph

object graph

mapping:o1 b1o2 a1o3 a1e f

Page 12: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 12

Lack of Knowledge

• Objects of a given class may be very different.

• We want to go down edges without looking ahead!

• We don’t want to go down edges that are guaranteed to be unsuccessful (never reaching a target object).

Page 13: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 13

Object graph conforms to class graph

• The object graph O must follow the rules of the class graph: the object graph cannot contain more information than the class graph allows.

For all edges e(o1,o2) in the object graph:e(o1, o2) implies class(o1) (<= .e .=> ) class(o2) in the class graph

Page 14: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 14

From dynamic to static characterization

From o1 of class c1, follow edge e iff there is some object graph O and some o2, o3 s.t.

1. e(o1,o2), 2. O*(o2,o3), and 3. class(o3) <= c2

From o1 of class c1, follow edge e iff there are classes c’, c’’ s.t.

1. c1 <=.e.=> c’2. c’ (<=.C.=>)* c’’ and 3. c’’ <= c2

Let c’ be class(o2), c’’ be class(o3)

Page 15: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 15

Relational Formulation

From object o of class c1, to get to c2, follow edges in the set

POSS(c1,c2,o)={e | c1 <=.e.=> (<=.C.=>)* <= c2 }

Can easily compute these sets for every c1, c2 via transitive-closure algorithms.POSS = abbreviation for: following these edges it is still possible to reach a c2-object for some c1-object rooted at o.

from c1 to c2

Page 16: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 16

Generalizations

• More complex strategies

• “from c1 through c2 to c3”– Use “waypoint navigation”; get to a c2 object,

then search for a c3 object.

• More complex strategy graphs also doable in this framework

Page 17: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 17

Traversal algorithms

• Rename POSS to FIRST.

• Applications of FIRST for strategies of the form : from c1 through c2 through … to ck.

Page 18: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 18

Definition of R-path

• Let R = (c1, … ,ck) be a non-empty sequence of classes. Let p = (o1, … , oN) be a path in O. We say that p is an R-path iff there is a subsequence oj1, … ,ojk of p such that for each i, oji has type ci and jk=N, (that is the last element of the path must be a part of the subsequence).

Page 19: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 19

Minimal R-paths

• We say that an R-path is minimal iff it has no initial segment that is also an R-path.

Page 20: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 20

Algorithm search(o,R)(visit all endpoints of minimal R-

paths)Let (c1, … ,cn) be the classes such that R = (c1, … ,cn).

1. If o does not have type c1, then for each e in FIRST(class(o), c1) and each o’ such that e(o,o’), do search(o’, R).

2. If o has type c1, and R=(c1), then do visit(o).

3. If o has type c1, and R=(c1, c2, … ,cn), then do search(o,(c2, … ,cn)).

Page 21: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 21

Cyclic and acyclic object graphs

• If the object graph is acyclic, algorithm search will terminate, since every step either decreases the longest chain of links in the object graph or decreases the length of R.

• If the object graph is cyclic, then we need to mark each searched object with the state R in which it was reached (to not visit it again in the same state).

Page 22: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 22

Extra Slides

Page 23: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 23

X2

X1

X3

S Y2

Y1

Y3

Z2

Z1

Z3

T

x

y

z

t

x31:X3 y31:Y3 z31:Z3 t1:Ts1:Sx y z t

go down x iff S <=.x. =>(<=.C.=>)*<=) T

StrategyS -> T

Example A

Page 24: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 24

X2

X1

X3

S Y2

Y1

Y3

Z2

Z1

Z3

T

x

y

z

t

x31:X3 y31:Y3 z31:Z3 t1:Ts1:Sx y z t

go down x iff S <=.x. =>.(<=.C.=>)*.<=) T

StrategyS -> T

Example A

<=,=>notused

Page 25: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 25

X2

X1

X3

S Y2

Y1

Y3

Z2

Z1

Z3

T

x

y

z

t

x31:X3 y31:Y3 z31:Z3 t1:Ts1:Sx y z t

go down x iff S <=.x. =>.(<=.C.=><=.C.=><=.C=>).<=) T

StrategyS -> T

<=,=>notused

Example A

Page 26: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 26

Example B

A

R

BX

S

D

0..1

0..1

0..1

C

T0..1

A -> TT -> D

A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .

:A

:R :S

:C :D

classgraph

strategyclass dictionary

object graph “r”

POSS(c1,c2,o)={e | c1 e.C* c2 }

Page 27: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 27

Example B1

A

R

BX

S

D

0..1

0..1

0..1

C

T0..1

A -> TT -> D

A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .

a1:A

r1:R s1:S

:C :D

classgraph

strategyclass dictionary

object graph “r”

POSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 0 edges

POSS(c1,c2,o)={e | c1 e.C* c2 }

Page 28: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 28

Example B1

A

R

BX

S

D

0..1

0..1

0..1

C

T0..1

A -> TT -> D

A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .

a1:A

r1:R s1:S

:C :D

classgraph

strategyclass dictionary

object graph “r”

POSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 0 edges

object graph slice

POSS(c1,c2,o)={e | c1 e.C* c2 }

Page 29: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 29

Example B2

A

R

BX

S

D

0..1

0..1

0..1

C

T0..1

A -> TT -> D

a1:A

r1:R

s1:Sc1:C

:D

classgraph

strategyPOSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 1 edgePOSS(T,D,t1) = 1 edgePOSS(R,D,r2) = 1 edge

t1:T

r2:R

c2:C

d2:D

s2:S

object graph “r t”

POSS(c1,c2,o)={e | c1 e.C* c2 }

object graph slice

Page 30: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 30

Example Cstrategy SG:{A -> B B -> C}

A

B

C

X

xx

b

c

class graph

A B C

Strategy s t

c

BOpt

Empty

Object graph

OG : A X R X COG’: A X B X CSG : A B C

:A

c2:C

x1:X

:R

x2:X

c1:C

c3:C

e1:Empty SR

Only node paths shown for space reasons

Page 31: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 31

Example C1strategy SG:{A -> S S -> C}

A

B

C

X

xx

b

c

class graph

A S C

Strategy s t

c

BOpt

Empty

Object graph

OG : A X R X OG’: A X B X SG : A B CG : A X Bopt B X

:A

c2:C

x1:X

:R

x2:X

c1:C

c3:C

e1:Empty SR

Only node paths shown for space reasons

early termination

Page 32: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 32

Example D

BusRoute BusStopList

BusStopBusList

Bus PersonList

Person

passengers

buses

busStops

waiting

0..*

0..*

0..*

S = from BusRoute through Bus to Person

NGasPowered

DieselPowered

Page 33: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 33

Example D1

Route1:BusRoute

:BusStopListbusStops

CentralSquare:BusStop

:PersonList

waiting

Paul:Person Seema:Person

BusListbuses

Bus15:DieselPowered

:PersonList

passengers

Joan:Person

Eric:Person

OG : BR BL DP PL POG’: BR BL B PL PS : BR B P

Only node paths shown for space reasons

S = from BusRoute through Bus to Person

Page 34: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 34

Example D2

Route1:BusRoute

:BusStopListbusStops

CentralSquare:BusStop

:PersonList

waiting

Paul:Person Seema:Person

BusListbuses

Bus15:DieselPowered

:PersonList

passengers

Joan:Person

Eric:Person

OG : BR BLOG’: BR BLS : BR

Only node paths shown for space reasons

S = from BusRoute via NGasPowered to Person

early termination

Page 35: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 35

Relational Formulation

From object o of class c1, to get to c2, follow edges in the set

POSS(c1,c2,o)={e | c1 <=.e.=> (<=.C.=>)* <= c2 }

POSS = abbreviation for: following these edges it is still possible to reach a c2-object for some c1-object rooted at o.

from c1 bypassing {x1,x2, … ,xn} to c2

Delete x1,x2, … ,xn and all edges incident with these nodesfrom the class graph (assumed to be different from c1, c2).

Page 36: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 36

Example D

BusRoute BusStopList

BusStopBusList

Bus PersonList

Person

passengers

buses

busStops

waiting

0..*

0..*

0..*

S = from BusRoute bybassing Bus to Person

NGasPowered

DieselPowered

Page 37: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 37

Example D

BusRoute BusStopList

BusStopBusList

PersonList

Person

buses

busStops

waiting

0..*

0..*

S = from BusRoute bybassing Bus to Person

NGasPowered

DieselPowered

Page 38: Navigation in Object Graphs

04/19/23 Navigation in Object Graphs 38

Conclusions

• Separation of concerns is also useful for defining programming language elements

– separate subgraph selected from

– how the subgraph is traversed (depth-first etc.)

• In earlier works: meaning of a traversal strategy for an object graph– was a traversal history

– now it is a subgraph of the object graph. A traversal history can be defined ...