©2007 Tarik Hadzic1 Lecture 11: Consistency Techniques 1. Arc Consistency 2. Directional...

Preview:

Citation preview

©2007 Tarik Hadzic 1

Lecture 11: Consistency Techniques

1. Arc Consistency 2. Directional Consistency3. Generalized Arc Consistency 

Efficient AI Programming

©2007 Tarik Hadzic 2

Today’s Program• Arc-Consistency

- AC-1 - AC-3, - AC-4

• Directional Consistency – DAC-1– Backtrack-free search

• Global Constraints– Generalized Arc Consistency– Domain Store Propagation

©2007 Tarik Hadzic 3

Bounded Constraint Inference

• Guarantee: any consistent instantiation of i-1 variable is extendible to any i-th variable

• Algorithms:– i=2: Arc-Consistency– i=3: Path-Consistency– i≥4: i-consistency

• i-consistency algorithms exponential in i. Trade-off between preprocessing and subsequent search

©2007 Tarik Hadzic 4

Arc-Consistency

©2007 Tarik Hadzic 5

Arc-Consistency

• Guarantee: any value in the domain of a single variable can be extended consistently by any other variable

• Example: network X={x,y}, Rxy: x<y, Dx=Dy={1,2,3}

1 •2 • 3 •

• 1• 2• 3

x < y

x y

©2007 Tarik Hadzic 6

Example

• Network X={x,y}, Rxy: x<y, Dx=Dy={1,2,3}

Not Arc-Consistenty

1 •2 • • 2

• 3

x < y

x

1 •2 • 3 •

• 1• 2• 3

x < y

x yArc-Consistent

©2007 Tarik Hadzic 7

Definition

• Given constraint problem <X,D,C> and constraint Cij(Sij,Rij) in C

• An arc (xi, xj) is arc-consistent iff for every ai Di there exists aj Dj such that (ai,aj) Rij

• If (xi, xj) is arc-consistent, it doesn’t imply that (xj, xi) is arc-consistent.

• A CSP <X,D,C> is arc-consistent iff all of its arcs are arc-consistent

©2007 Tarik Hadzic 8

Revise ((xi),xj)

1. deleted false

2. for each ai Di

3. if there is no aj Dj, (ai,aj) Rij

4. then delete ai from D, deleted true5. endif6. endfor 7. return deleted

• Complexity?

• O(k2) where k bounds the domain size

©2007 Tarik Hadzic 9

Revise ((xi),xj)

1 •2 •

• 1• 2• 3

x < y

x y

1 •2 • 3 •

• 2• 3

x < y

x y

1 •2 • 3 •

• 1• 2• 3

x < y

x y Revise((x),y)

Revise((y),x)

©2007 Tarik Hadzic 10

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

• • •

y• • •

z• • •

•Revise((x),z)

©2007 Tarik Hadzic 11

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

• •

y• • •

z• • •

•Revise((x),z)

•Revise((y),x)

©2007 Tarik Hadzic 12

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

• •

y • •

z• • •

•Revise((x),z)

•Revise((z),y)•Revise((y),x)

©2007 Tarik Hadzic 13

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

• •

y • •

z • •

•Revise((x),z)

•Revise((z),y)

•Revise((x),z)

•Revise((y),x)

©2007 Tarik Hadzic 14

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

y • •

z • •

•Revise((x),z)

•Revise((z),y)

•Revise((x),z)•Revise((y),x)

•Revise((y),x)

©2007 Tarik Hadzic 15

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

y •

z • •

•Revise((x),z)

•Revise((z),y)•Revise((x),z)•Revise((y),x)•Revise((z),y)

•Revise((y),x)

©2007 Tarik Hadzic 16

Revise ((xi),xj)

To achieve arc-consistency, apply Revise until no change in the domain of any variable in the

network

x

y •

z •

•Revise((x),z)

•Revise((z),y)•Revise((x),z)•Revise((y),x)•Revise((z),y)

•Revise((y),x)

©2007 Tarik Hadzic 17

AC-1 ()1. repeat2. for every {xi,xj} participating in a constraint3. Revise((xi),xj)4. Revise((xj),xi)5. endfor6. until no domain changed

• Complexity?

• O(enk3) where n variables, e binary constraints, k bounds the domain size

©2007 Tarik Hadzic 18

AC-3 ()

• Improvement over AC-1– No need to process all constraints

– Revise((xi),xj) is processed only when Dj is reduced

– queue maintains pairs (xi,xj) involved in a constraint where Dj is reduced

– Initially, for every constraint Cij, (xi,xj) and (xj,xi) are added to queue

©2007 Tarik Hadzic 19

AC-3 ()

1. for every constraint Cij

2. Q ← Q U {(xi,xj),(xj,xi)}3. endfor4. while Q ≠ {}

5. select and delete (xi,xj) from Q

6. Revise((xi),xj)

7. if Revise((xi),xj)=true then

8. Q ← Q U {(xk,xi), k ≠i, k≠j}9. endif10. endwhile

©2007 Tarik Hadzic 20

Example: AC-3 ()X = {x,y,z},

Dz={2,5}, Dx={2,5}, Dy={2,4};

Rzx: ”z divides x”; Ryz: “z divides y”

2,5

2,5 2,4

x

z

y

Q = {(z,x),(x,z),(z,y),(y,z)}

©2007 Tarik Hadzic 21

Example: AC-3 ()X = {x,y,z},

Dz={2,5}, Dx={2,5}, Dy={2,4};

Rzx: ”z divides x”; Rxz: “z divides y”

2,5

2,5 2,4

x

z

y

Q = {(z,x),(x,z),(z,y),(y,z)}

Revise((z),x)

No effect!

©2007 Tarik Hadzic 22

Example: AC-3 ()X = {x,y,z},

Dz={2,5}, Dx={2,5}, Dy={2,4};

Rzx: ”z divides x”; Rxz: “z divides y”

2,5

2,5 2,4

x

z

y

Q = {(x,z),(z,y),(y,z)}

Revise((x),z)

No effect!

©2007 Tarik Hadzic 23

Example: AC-3 ()X = {x,y,z},

Dz={2,5}, Dx={2,5}, Dy={2,4};

Rzx: ”z divides x”; Ryz: “z divides y”

2

2,5 2,4

x

z

y

Q = {(y,z),(x,z)}

Revise((y),z)

No effect!

©2007 Tarik Hadzic 24

Example: AC-3 ()X = {x,y,z},

Dz={2,5}, Dx={2,5}, Dy={2,4};

Rzx: ”z divides x”; Rxz: “z divides y”

2

2,5 2,4

x

z

y

Q = {(x,z)}

Revise((x),z)

Delete 5 from Dx

No constraints added to queue!

©2007 Tarik Hadzic 25

Example: AC-3 ()X = {x,y,z},

Dz={2,5}, Dx={2,5}, Dy={2,4};

Rzx: ”z divides x”; Rxz: “z divides y”

2

2 2,4

x

z

y

Q = {}

AC-3 terminates!

©2007 Tarik Hadzic 26

AC-4 ()• Optimal performance O(ek2)• Does not use Revise• For every value a Di maintains counter(xi,

xj,a) : number of values in Dj consistent with xi=a

2,5

2,5 2,4

x

z

y

• counter(z,y,2) =

• counter(z,y,5) =

• counter(z,x,2) =

• counter(z,x,5) =

2

0!

1

1

No counters between x and y

©2007 Tarik Hadzic 27

AC-4 ()• If counter(xi,xj,a)=0 then (xi,a) is unsupported• List Q: maintains unsupported (xi,a) pairs• S(xj,a) : all values in other variable domains supported

by (xj,a)• In each step AC-4:

– Picks and removes unsupported value from Q – Updates counters of potentially affected values

©2007 Tarik Hadzic 28

AC-4 ()

©2007 Tarik Hadzic 29

AC-4 ()

©2007 Tarik Hadzic 37

Directional Arc Consistency

©2007 Tarik Hadzic 38

Motivation

• Determining amount of inference for backtrack-free guarantee

• Restrict inference relative to a given ordering

• Arc consistency unnecessary when solution generated along a fixed ordering

©2007 Tarik Hadzic 39

Directional Arc-Consistency A network is directional arc-consistent relative to order d=(x1,…,xn) iff every arc (xi,xj) is arc-consistent whenever i < j in the ordering

DAC(<X,D,C>)

• for i=n to 1 by -1

• for each j<i such that Cij C

• Revise((xj),xi)

©2007 Tarik Hadzic 40

Example

<X,D,C>, X={x1,x2,x3,x4}

D1={red,white,black}, D2={green,white,black},

D3={red,white,blue}, D4={white,blue,black}

R12 : x1 = x2 R13: x1 = x3 R34: x3 = x4

d = (x1,x2,x3,x4)x4

x3

x2

x1

©2007 Tarik Hadzic 41

Example

x4

x3

x2

x1

D1={red,white,black}

D2={green,white,black}

D3={red,white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

©2007 Tarik Hadzic 42

ExampleD1={red,white,black}

D2={green,white,black}

D3={red,white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

Revise((x3),x4)

©2007 Tarik Hadzic 43

ExampleD1={red,white,black}

D2={green,white,black}

D3={red,white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

Delete red from D3!

©2007 Tarik Hadzic 44

ExampleD1={red,white,black}

D2={green,white,black}

D3={white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

Revise((x1),x3)

©2007 Tarik Hadzic 45

Example

D1={red,white,black}

D2={green,white,black}

D3={white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

Delete red, black from D1!

©2007 Tarik Hadzic 46

ExampleD1={white}

D2={green,white,black}

D3={white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

Revise((x1),x2)

©2007 Tarik Hadzic 47

ExampleD1={white}

D2={green,white,black}

D3={white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

No effect!

©2007 Tarik Hadzic 48

ExampleD1={white}

D2={green,white,black}

D3={white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

x4

x3

x2

x1

DAC terminates!

©2007 Tarik Hadzic 49

ExampleD1={white}

D2={green,white,black}

D3={white,blue}

D4={white,blue,black}

R12: x1 = x2

R13: x1 = x3

R34: x3 = x4

Backtrack-free assignment:

1. x1 = white

2. x2 = white

3. x3 = white

4. x4 = white

©2007 Tarik Hadzic 50

Directional Arc-Consistency

DAC(<X,D,C>)

• for i=n to 1 by -1

• for each j<i such that Cij C

• Revise((xj),xi)

Complexity: O(ek2)

©2007 Tarik Hadzic 51

Global Constraints and Generalized Arc-Consistency

©2007 Tarik Hadzic 52

Definition

• Given constraint problem <X,D,C> and (n-ary) constraint C’C, C’ = (R,S)

• Variable x is (generalized) arc-consistent relative to constraint (R,S) iff for every a Dx there exists a tuple in the domains of variables in S, t R such that t[x] = a

©2007 Tarik Hadzic 53

Example

• Dx = [0,15], Dy = [0,15], Dz = [0,15]

• x+y+z 15, z ≥ 13

• Dx ← [0,2], Dy ← [0,2]

• Alldiff(x1,…,xn)

©2007 Tarik Hadzic 54

Modern Solver Architecture

D1, D2, …, Dn

C1

C2

C3

1. Each Global Constraint Prunes Domains (highest level of pruning is GAC)

2. Constraint Store ”notifies” affected global constraints

Global Constraints

Constraint Store (Domain Store)

Recommended