Class2: Constraint Networks Rina Dechter Dbook: chapter 2-3, - - PowerPoint PPT Presentation

class2 constraint networks
SMART_READER_LITE
LIVE PREVIEW

Class2: Constraint Networks Rina Dechter Dbook: chapter 2-3, - - PowerPoint PPT Presentation

Algorithms for Reasoning with graphical models Class2: Constraint Networks Rina Dechter Dbook: chapter 2-3, Constraint book: chapters 2 and 4 class2 276 2018 Text Books class2 276 2018 Road Map Graphical models Constraint networks


slide-1
SLIDE 1

Algorithms for Reasoning with graphical models

Class2: Constraint Networks

Rina Dechter

class2 276 2018

Dbook: chapter 2-3, Constraint book: chapters 2 and 4

slide-2
SLIDE 2

Text Books

class2 276 2018

slide-3
SLIDE 3

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints

 Variable elimination for CNFs  Variable elimination for Linear Inequalities  Constraint propagation

 Search  Probabilistic Networks

class2 276 2018

slide-4
SLIDE 4

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints

 Variable elimination for CNFs  Variable elimination for Linear Inequalities  Constraint propagation

 Search  Probabilistic Networks

class2 276 2018

slide-5
SLIDE 5

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints

 Variable elimination for CNFs  Variable elimination for Linear Inequalities  Constraint propagation

 Search  Probabilistic Networks

class2 276 2018

slide-6
SLIDE 6

Sudoku – Approximation: Constraint Propagation

Each row, column and major block must be alldifferent “Well posed” if it has unique solution: 27 constraints

2 3 4 6

2

  • Variables: empty slots
  • Domains =

{1,2,3,4,5,6,7,8,9}

  • Constraints:
  • 27 all-different
  • Constraint
  • Propagation
  • Inference

class2 276 2018

slide-7
SLIDE 7

Sudoku

Each row, column and major block must be alldifferent “Well posed” if it has unique solution

class2 276 2018

slide-8
SLIDE 8

A B

red green red yellow green red green yellow yellow green yellow red

Example: map coloring

Variables - countries (A,B,C,etc.) Values - colors (red, green, blue) Constraints:

etc. , E D D, A B, A   

C A B D E F G

A

Const Constraint aint Netw Networ

  • rks

ks

A B E G D F C

Constraint graph

class2 276 2018

slide-9
SLIDE 9

Example: map coloring

Variables - countries (A,B,C,etc.) Values - colors (e.g., red, green, yellow) Constraints:

etc. , E D D, A B, A   

A B C D E… red

green

red

green blue

red

blue

green

green blue

… … … …

green

… … … … red red

blue

red

green

red

Constraint Satisfaction Tasks

Are the constraints consistent? Find a solution, find all solutions Count all solutions Find a good (optimal) solution

class2 276 2018

slide-10
SLIDE 10

Constraint Network

} ,..., {

1 n

X X X 

 A constraint network is: R=(X,D,C)

X variables

D domain

C constraints

R expresses allowed tuples over scopes

A solution is an assignment to all variables that satisfies all constraints (join of all relations).

Tasks: consistency?, one or all solutions, counting, optimization

} ,... { }, ,..., {

1 1 k i n

v v D D D D  

) , ( } ,... {

1 i i i t

R S C C C C  

class2 276 2018

slide-11
SLIDE 11

Crossword Puzzle

 Variables: x1, …, x13  Domains: letters  Constraints: words from

{HOSES, LASER, SHEET, SNAIL, STEER, ALSO, EARN, HIKE, IRON, SAME, EAT, LET, RUN, SUN, TEN, YES, BE, IT, NO, US}

class2 276 2018

slide-12
SLIDE 12

class2 276 2018

Crossword Puzzle

I

slide-13
SLIDE 13

The Queen Problem

The network has four variables, all with domains Di = {1, 2, 3, 4}. (a) The labeled chess board. (b) The constraints between variables.

class2 276 2018

slide-14
SLIDE 14

The Queen Problem

The network has four variables, all with domains Di = {1, 2, 3, 4}. (a) The labeled chess board. (b) The constraints between variables.

class2 276 2018

slide-15
SLIDE 15

Varieties of Constraints

Unary constraints involve a single variable,

e.g., SA ≠ green

Binary constraints involve pairs of variables,

e.g., SA ≠ WA

Higher-order constraints involve 3 or more variables,

e.g., cryptarithmetic column constraints

class2 276 2018

slide-16
SLIDE 16

Constraint’s Representations

 Relation: allowed tuples  Algebraic expression:  Propositional formula:  Semantics: by a relation

Y X Y X    , 10

2

c b a

 ) (

3 1 2 2 3 1 Z Y X

class2 276 2018

slide-17
SLIDE 17

Partial Solutions

Not all consistent instantiations are part of a solution: (a) A consistent instantiation that is not part of a solution. (b) The placement of the queens corresponding to the solution (2, 4, 1, 3). (c) The placement of the queens corresponding to the solution (3, 1, 4, 2).

class2 276 2018

slide-18
SLIDE 18

Constraint Graphs:

Primal, dual and hypergraphs

A (primal) constraint graph: a node per variable arcs connect constrained variables. A dual constraint graph: a node per constraint’s scope, an arc connect nodes sharing variables =hypergraph class2 276 2018

When variables are squares:

slide-19
SLIDE 19

Graph Concepts

class2 276 2018

slide-20
SLIDE 20

Propositional Satisfiability

 = {(¬C), (A v B v C), (¬A v B v E), (¬B v C v D)}.

class2 276 2018

slide-21
SLIDE 21

cost

i j

f f  

Given a telecommunication network (where each communication link has various antenas) , assign a frequency to each antenna in such a way that all antennas may operate together without noticeable interference.

Encoding?

Variables: one for each antenna Domains: the set of available frequencies Constraints: the ones referring to the antennas in the same communication link

Example: Radio Link Assignment

class2 276 2018

slide-22
SLIDE 22

Constraint graphs of 3 instances of the Radio frequency assignment problem in CELAR’s benchmark

class2 276 2018

slide-23
SLIDE 23

Operations With Relations

 Intersection  Union  Difference  Selection  Projection  Join  Composition

class2 276 2018

slide-24
SLIDE 24

Join :

Logical AND:

x1 x2

a a b b

x2 x3

a a a b b a

x1 x2 x3 a a a a a b b b a

Local Functions Combination

g f g f

x1 x2

f a a true a b false b a false b b true

x2 x3

g a a true a b true b a true b b false

x1 x2 x3 h a a a

true

a a b

true

a b a

false

a b b

false

b a a

false

b a b

false

b b a

true

b b b

false

class2 276 2018

slide-25
SLIDE 25

Example of Selection, Projection and Join

class2 276 2018

slide-26
SLIDE 26

Global View of the Problem

x1 x2 x3 h a a a

true

a a b

true

a b a

false

a b b

false

b a a

false

b a b

false

b b a

true

b b b

false

x1 x2

a a b b

x2 x3

a a a b b a

x1 x2 x3 a a a a a b b b a

C1 C2 Global View

What about counting?

x1 x2 x3 h a a a

1

a a b

1

a b a a b b b a a b a b b b a

1

b b b

Number of true tuples Sum over all the tuples true is 1 false is 0 logical AND? TASK

class2 276 2018

slide-27
SLIDE 27

class2 276 2018

The minimal network,

An extreme case of re-parameterization

slide-28
SLIDE 28

The N-queens Constraint Network

The network has four variables, all with domains Di = {1, 2, 3, 4}. (a) The labeled chess board. (b) The constraints between variables. Solutions are: (2,4,1,3) (3,1,4,2)

class2 276 2018

slide-29
SLIDE 29

class2 276 2018

Figure 2.11: The 4-queens constraint network: (a) The constraint graph. (b) The minimal binary constraints. (c) The minimal unary constraints (the domains).

Solutions are: (2,4,1,3) (3,1,4,2)

slide-30
SLIDE 30

The Minimal Network

 The minimal network is perfectly explicit for

binary and unary constraints:

 Every pair of values permitted by the minimal

constraint is in a solution.

class2 276 2018

slide-31
SLIDE 31

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints

 Variable elimination for CNFs  Variable elimination for Linear Inequalities  Constraint propagation

 Search  Probabilistic Networks

class2 276 2018

slide-32
SLIDE 32

Bucket Elimination

Adaptive Consistency (Dechter & Pearl, 1987)

Bucket E: E D, E  C Bucket D: D A Bucket C: C B Bucket B: B  A Bucket A: A C

width induced

  • *

*

w )) exp(w O(n : Complexity

contradiction

=

D = C B = A

=

class2 276 2018

slide-33
SLIDE 33

The Idea of Elimination

project and join E variable Eliminate   

EC DBC EB ED DBC

R R R R

3 value assignment

D B C RDBC

eliminating E

class2 276 2018

     

E D

A

C B

} 2 , 1 { } 2 , 1 { } 2 , 1 { } 2 , 1 { } 3 , 2 , 1 {

slide-34
SLIDE 34

d

  • rdering

along width induced

  • (d)

,

* *

w (d))) exp(w O(n : Complexity

     

E D

A

C B

} 2 , 1 { } 2 , 1 { } 2 , 1 { } 2 , 1 { } 3 , 2 , 1 {

: ) ( A B : ) ( B C : ) ( A D : ) ( B E C, E D, E : ) ( A Bucket B Bucket C Bucket D Bucket E Bucket      

A E D C B

: ) ( E B : ) ( E C , B C : ) ( E D : ) ( B A D, A : ) ( E Bucket B Bucket C Bucket D Bucket A Bucket      

E A D C B || RD

BE ,

|| RE || RDB || RDCB || RACB || RAB RA RC

BE

Bucket-Elimination

class2 276 2018

slide-35
SLIDE 35

The Induced-Width

Width along d, w(d):

max # of previous parents

Induced width w*(d):

The width in the ordered induced graph

Induced-width w*:

Smallest induced-width

  • ver all orderings

Finding w*

NP-complete (Arnborg, 1985) but greedy heuristics (min-fill).

class2 276 2018

slide-36
SLIDE 36

Adaptive-Consistency, Bucket-Elimination

Initialize: partition constraints into For i=n down to 1 along d ( process in reverse order) for all relations do (join all relations and “project-out” )

n

bucket bucket ,...,

1 i m

bucket R R  ,...,

1

) (

) ( j X j new

R R

i

 

i

X

If is not empty, add it to where k is the largest variable index in Else problem is unsatisfiable

new

R

, , i k bucketk 

new

R

Return the set of all relations (old and new) in the buckets

class2 276 2018

slide-37
SLIDE 37

Algorithms for Reasoning with graphical models

Class3

Rina Dechter

class2 276 2018

slide-38
SLIDE 38

Example: deadends, backtrack-freeness

class2 276 2018

1,2 1,2 1,2,3 1,2,3 = = ≠ ≠ A A D B C Assign values in the order D,B,C,A before and after adaptive-consistence Order A,B,C,D, order A,B,D,C

slide-39
SLIDE 39

Adaptive-consistency generates a constraint network that is backtrack-free (can be solved without dead-ends).

The time and space complexity of adaptive-consistency along ordering d is time and memory exponential in w*(d) .

Therefore, problems having bounded induced width are tractable (solved in polynomial time).

trees ( w*=1),

series-parallel networks ( w*=2 ),

and in general k-trees ( w*=k).

class2 276 2018

Properties of Adaptive-Consistency

slide-40
SLIDE 40

Solving Trees

(Mackworth and Freuder, 1985)

Adaptive consistency is linear for trees and equivalent to enforcing directional arc-consistency (recording only unary constraints)

class2 276 2018

slide-41
SLIDE 41

Tree Solving is Easy

1,2,3 1,2,3 1,2,3 1,2,3 1,2,3 1,2,3 1,2,3

< < Y X Z T S R U

class2 276 2018

slide-42
SLIDE 42

Tree Solving is Easy

1,2,3 1,2,3 1,2,3 1,2,3 1,2,3 1,2,3 1,2,3

< < Y X Z T S R U

class2 276 2018

slide-43
SLIDE 43

Tree Solving is Easy

1,2,3 1,2,3 1,2,3 1,2,3 1,2 1,2 1,2,3

< < Y X Z T S R U

class2 276 2018

slide-44
SLIDE 44

Tree Solving is Easy

1,2,3 1,2,3 1,2,3 1,2,3 1,2 1,2 1,2,3

< < Y X Z T S R U

class2 276 2018

slide-45
SLIDE 45

Tree Solving is Easy

1,2,3 1,2,3 1,2,3 1,2,3 1,2 1,2 1

< < Y X Z T S R U

class2 276 2018

slide-46
SLIDE 46

Tree Solving is Easy

1,2,3 1,2,3 1,2,3 1,2,3 2 2 1

< < Y X Z T S R U

class2 276 2018

slide-47
SLIDE 47

Tree Solving is Easy

3 3 3 3 2 2 1

< < Y X Z T S R U

class2 276 2018

slide-48
SLIDE 48

Tree Solving is Easy

3 3 3 3 2 2 1

< < Y X Z T S R U

Adaptive-consistency is linear time because induced-width is 1 (Constraint propagation Solves trees in linear time)

class2 276 2018

slide-49
SLIDE 49

Example: crossword puzzle

slide-50
SLIDE 50

class2 276 2018

Adaptive-Consistency

  • n the Crossword Puzzle
slide-51
SLIDE 51

class2 276 2018

Adaptive-Consistency

  • n the Crossword Puzzle
slide-52
SLIDE 52

class2 276 2018

Adaptive-Consistency

  • n the Crossword Puzzle
slide-53
SLIDE 53

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints

 Variable elimination for CNFs  Variable elimination for Linear Inequalities  Constraint propagation

 Search  Probabilistic Networks

class2 276 2018

slide-54
SLIDE 54

Gausian and Boolean Propagation, Resolution

 Linear inequalities  Boolean constraint

propagation, unit resolution

2 , 2   y x

) ( C A

     13 , 15 z z y x

 ) ( ), ( B C B A

class2 276 2018

slide-55
SLIDE 55

class2 276 2018

The Effect of Resolution on Its Graph

(~C) (AVBVC) (~AvBvE)(~B,C,E)

slide-56
SLIDE 56

Directional Resolution  Adaptive Consistency

)) exp( ( : space and time DR )) (exp( | |

* *

w n O w O bucketi 

class2 276 2018

(~C) (AVBVC) (~AvBvE)(~B,C,E)

slide-57
SLIDE 57

Directional Resolution  Adaptive Consistency

)) exp( ( : space and time DR )) (exp( | |

* *

w n O w O bucketi 

class2 276 2018

(~C) (AVBVC) (~AvBvE)(~B,C,E)

slide-58
SLIDE 58

Directional Resolution  Adaptive Consistency

)) exp( ( : space and time DR )) (exp( | |

* *

w n O w O bucketi 

class2 276 2018

(~C) (AVBVC) (~AvBvE)(~B,C,E)

slide-59
SLIDE 59

class2 276 2018

Directional Resolution  Adaptive Consistency

slide-60
SLIDE 60

class2 276 2018

Directional Resolution

slide-61
SLIDE 61

class2 276 2018

History

1960 – resolution-based Davis-Putnam algorithm

1962 – resolution step replaced by conditioning (Davis, Logemann and Loveland, 1962) to avoid memory explosion, resulting into a backtracking search algorithm known as Davis-Putnam (DP), or DPLL procedure.

The dependency on induced width was not known in 1960.

1994 – Directional Resolution (DR), a rediscovery of the original Davis-Putnam, identification of tractable classes (Dechter and Rish, 1994).

slide-62
SLIDE 62

Properties of DR

class2 276 2018

slide-63
SLIDE 63

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints  Variable elimination for CNFs  Greedy search for induced-width orderings  Variable elimination for Linear Inequalities

 Constraint propagation  Search  Probabilistic Networks class2 276 2018

slide-64
SLIDE 64

Graph Properties

 Finding a minimum induced-width

  • rdering is hard (NP-complete, lots of

literature). So we have approximation greedy schemes.

class2 276 2018

slide-65
SLIDE 65

class2 276 2018

Greedy Algorithms for Induced-Width

 Min-width ordering  Min-induced-width ordering  Max-cardinality ordering  Min-fill ordering  Chordal graphs  Hypergraph partitionings

(Project: present papers on induced-width, run algorithms for induced-width on new benchmarks…)

slide-66
SLIDE 66

Min-width Ordering

Proposition: algorithm min-width finds a min-width ordering of a graph Complexity:? O(e)

class2 276 2018

slide-67
SLIDE 67

Greedy Orderings Heuristics

min-induced-width (miw) input: a graph G = (V;E), V = {v1; :::; vn}

  • utput: A miw ordering of the nodes d = (v1; :::; vn).
  • 1. for j = n to 1 by -1 do
  • 2. r  a node in V with smallest degree.
  • 3. put r in position j.
  • 4. connect r's neighbors: E  E union {(vi; vj)| (vi; r) in E; (vj ; r) 2 in E},
  • 5. remove r from the resulting graph: V V - {r}.

min-fill (min-fill) input: a graph G = (V;E), V = {v1; :::; vn}

  • utput: An ordering of the nodes d = (v1; :::; vn).
  • 1. for j = n to 1 by -1 do
  • 2. r a node in V with smallest fill edges for his parents.
  • 3. put r in position j.
  • 4. connect r's neighbors: E E union {(vi; vj)| (vi; r) 2 E; (vj ; r) in E},
  • 5. remove r from the resulting graph: V V –{r}.

Theorem: A graph is a tree iff it has both width and induced-width of 1.

class2 276 2018

slide-68
SLIDE 68

class2 276 2018

Example

slide-69
SLIDE 69

class2 276 2018

Example

slide-70
SLIDE 70

class2 276 2018

Chordal Graphs; Max-Cardinality Ordering

 A graph is chordal if every cycle of length at

least 4 has a chord

 Finding w* over chordal graph is easy using the

max-cardinality ordering

 If G* is an induced graph of it is chordal  K-trees are special chordal graphs.  Finding the max-clique in chordal graphs is

easy (just enumerate all cliques in a max- cardinality ordering

slide-71
SLIDE 71

class2 276 2018

Max-Cardinality Ordering

slide-72
SLIDE 72

class2 276 2018

Example

We see again that G in the Figure (a) is not chordal since the parents of A are not connected in the max- cardinality ordering in Figure (d). If we connect B and C, the resulting induced graph is chordal.

slide-73
SLIDE 73

Which Greedy Algorithm is Best?

 MinFill, prefers a node who add the least

number of fill-in arcs.

 Empirically, fill-in is the best among the

greedy algorithms (MW,MIW,MF,MC)

 Complexity of greedy orderings?  MW is O(?), MIW: O(?) MF (?) MC is O(mn)

class2 276 2018

slide-74
SLIDE 74

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints  Variable elimination for CNFs  Greedy search for induced-width orderings  Variable elimination for Linear Inequalities

 Constraint propagation  Search  Probabilistic Networks class2 276 2018

slide-75
SLIDE 75

Linear Inequalities

class2 276 2018

slide-76
SLIDE 76

class2 276 2018

Linear Inequalities: Fourier Elimination

slide-77
SLIDE 77

Directional linear elimination, DLE : generates a backtrack-free representation

class2 276 2018

slide-78
SLIDE 78

class2 276 2018

Example

slide-79
SLIDE 79

Algorithms for Reasoning with graphical models

Class4

Rina Dechter

class2 276 2018

slide-80
SLIDE 80

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination for Constraints

 Variable elimination for CNFs  Variable elimination for Linear Inequalities  Constraint propagation (ch 2 Dechter2)

 Search  Probabilistic Networks

class2 276 2018

slide-81
SLIDE 81

Sudoku – Approximation: Constraint Propagation

Each row, column and major block must be alldifferent “Well posed” if it has unique solution: 27 constraints

2 3 4 6

2

  • Variables: empty slots
  • Domains =

{1,2,3,4,5,6,7,8,9}

  • Constraints:
  • 27 all-different
  • Constraint
  • Propagation
  • Inference

class2 276 2018

slide-82
SLIDE 82

Approximating Inference: Local Constraint Propagation

 Problem: bucket-elimination/tree-clustering

algorithms are intractable when induced width is large

 Approximation: bound the size of recorded

dependencies, i.e. perform local constraint propagation (local inference)

class2 276 2018

slide-83
SLIDE 83

From Global to Local Consistency

class2 276 2018

slide-84
SLIDE 84

Arc-Consistency

A binary constraint R(X,Y) is arc-consistent w.r.t. X is every value In x’s domain has a match in y’s domain.

Y X R R

Y X

   constraint }, 3 , 2 , 1 { }, 3 , 2 , 1 {

Only domains are reduced:

X Y XY X

D R R

class2 276 2018

slide-85
SLIDE 85

Arc-Consistency

Definition: Given a constraint graph G,

A variable Vi is arc-consistent relative to Vj iff for every value aDVi there exists a value bDVj | (a, b)RVi,Vj.

The constraint RVi,Vj is arc-consistent iff

Vi is arc-consistent relative to Vj and

Vj is arc-consistent relative to Vi.

A binary CSP is arc-consistent iff every constraint (or sub-graph

  • f size 2) is arc-consistent

1 2 2 3 1 2 3 1 2 3 Vi Vj Vj Vi

class2 276 2018

slide-86
SLIDE 86

3 2, 1, 3 2, 1, 3 2, 1, 1  X, Y, Z, T  3 X  Y Y = Z T  Z X  T X Y T Z 3 2, 1,

 =  

Ar Arc-consis consistenc tency

class2 276 2018

slide-87
SLIDE 87

1  X, Y, Z, T  3 X  Y Y = Z T  Z X  T X Y T Z

 =  

1 3 2 3

X Y XY X

D R R

Arc-consistency

class2 276 2018

slide-88
SLIDE 88

AC-1

) (

3

enk O 

Complexity (Mackworth and Freuder, 1986):

e = number of arcs, n variables, k values

(ek^2, each loop, nk number of loops), best-case = ek

Arc-consistency is:

Complexity of AC-1: O(en𝑙3)

) (

2

ek 

class2 276 2018

slide-89
SLIDE 89

AC-3

) (

3

ek O

Complexity:

Best case O(ek), since each arc may be processed in O(2k)

class2 276 2018

slide-90
SLIDE 90

Arc-Consistency Algorithms

) (

3

ek O

AC-1: brute-force, distributed

AC-3, queue-based

AC-4, context-based, optimal

AC-5,6,7,…. Good in special cases

Important: applied at every node of search

n=number of variables, e=#constraints, k=domain size

Mackworth and Freuder (1977,1983), Mohr and Anderson, (1985)…

) (

3

nek O

) (

2

ek O

class2 276 2018

slide-91
SLIDE 91

Relational Distributed Arc- Consistency

Primal Dual

AB AD

AB

1 2 2 3

AD

1 2 2 3

A

AB AD

1 2 1 2 2 3 2 3

A B C D

3 2 1 A 3 2 1 B 3 2 1 D 3 2 1 C A < B

1 2 2 3

A < D

1 2 2 3

D < C

1 2 2 3

B = C

1 1 2 2 3 3

DC BC

D C B

AB BC

1 2 2 2 2 3 3 3

BC

1 1 2 2 3 3

DC

1 2 2 3

BC DC

2 2 1 2 3 3 2 3

AD DC

1 2 2 3

class2 276 2018

slide-92
SLIDE 92

Path-Consistency

A pair (x, y) is path-consistent relative to Z, if every consistent assignment (x, y) has a consistent extension to z.

class2 276 2018

slide-93
SLIDE 93

Example: Path-Consistency

class2 276 2018

slide-94
SLIDE 94

Directional i-Consistency

DCB

R

A E C D B

      

D C B E D C B E D C B E

: A B A : B B C : C A D C, D : D B E C, E D, E : E        Adaptive d-arc d-path

DB DC R

R ,

CB

R

D

R

C

R

D

R

class2 276 2018

slide-95
SLIDE 95

class2 276 2018

Variable Elimination

Eliminate variables

  • ne by one:

“constraint propagation” Solution generation after elimination is backtrack-free

3

slide-96
SLIDE 96

Road Map

 Graphical models  Constraint networks Model  Inference

 Variable elimination:

 Tree-clustering  Constraint propagation

 Search  Probabilistic Networks

class2 276 2018