48
1 Constraint Constraint Satisfaction Problems Satisfaction Problems

1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

Embed Size (px)

Citation preview

Page 1: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

1

Constraint Satisfaction Constraint Satisfaction ProblemsProblems

Page 2: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

2

Intro Example: 8-QueensIntro Example: 8-Queens

Generate-and-test: 88 combinations

Page 3: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

3

Intro Example: 8-QueensIntro Example: 8-Queens

Page 4: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

4

Constraint Satisfaction Constraint Satisfaction ProblemProblem

Set of variables {X1, X2, …, Xn}Each variable Xi has a domain Di of possible values Usually Di is discrete and finite

Set of constraints {C1, C2, …, Cp} Each constraint Ck involves a subset of

variables and specifies the allowable combinations of values of these variables

Assign a value to every variable such that all constraints are satisfied

Page 5: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

5

Example: 8-Queens Example: 8-Queens ProblemProblem

8 variables Xi, i = 1 to 8 Domain for each variable {1,2,…,8} Constraints are of the forms: Xi = k Xj k for all j = 1 to 8, ji Xi = ki, Xj = kj |i-j| | ki - kj|

for all j = 1 to 8, ji

Page 6: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

6

Example: Map ColoringExample: Map Coloring

• 7 variables {WA,NT,SA,Q,NSW,V,T}• Each variable has the same domain {red, green, blue}• No two adjacent variables have the same value: WANT, WASA, NTSA, NTQ, SAQ, SANSW, SAV,QNSW, NSWV

WA

NT

SA

Q

NSWV

T

WA

NT

SA

Q

NSWV

T

Page 7: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

7

Constraint GraphConstraint Graph

Binary constraints

T

WA

NT

SA

Q

NSW

V

Two variables are adjacent or neighbors if theyare connected by an edge or an arc

Page 8: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

8

Map ColoringMap Coloring

{}

WA=red WA=green WA=blue

WA=redNT=green

WA=redNT=blue

WA=redNT=greenQ=red

WA=redNT=greenQ=blue

WA

NT

SA

Q

NSWV

T

Page 9: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

9

Backtracking AlgorithmBacktracking Algorithm

CSP-BACKTRACKING(PartialAssignment a) If a is complete then return a X select an unassigned variable D select an ordering for the domain of X For each value v in D do

If v is consistent with a then Add (X= v) to a result CSP-BACKTRACKING(a) If result failure then return result

Return failure

CSP-BACKTRACKING({})

Page 10: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

10

QuestionsQuestions

1. Which variable X should be assigned a value next?

2. In which order should its domain D be sorted?

3. In which order should constraints be verified?

Page 11: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

11

Choice of VariableChoice of Variable

Map coloring

WA

NT

SA

Q

NSWV

T

WA

NT

SA

Page 12: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

12

Choice of VariableChoice of Variable

8-queen

Page 13: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

13

Choice of VariableChoice of Variable

Most-constrained-variable heuristic: Select a variable with the fewest

remaining values

= Fail First Principle

Page 14: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

14

Choice of VariableChoice of Variable

Most-constraining-variable heuristic: Select the variable that is involved in the largest

number of constraints on other unassigned variables= Fail First Principle again

WA

NT

SA

Q

NSWV

T

SA

Page 15: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

15

{}

Choice of ValueChoice of Value

WA

NT

SA

Q

NSWV

T

WA

NT

Page 16: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

16

Choice of ValueChoice of Value

Least-constraining-value heuristic: Prefer the value that leaves the largest subset

of legal values for other unassigned variables

{blue}

WA

NT

SA

Q

NSWV

T

WA

NT

Page 17: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

17

Choice of Constraint to Choice of Constraint to TestTest

Most-constraining-Constraint: Prefer testing constraints that are

more difficult to satisfy= Fail First Principle

Page 18: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

18

Constraint Propagation …Constraint Propagation …

… is the process of determining how the possible values of one variable affect the possible values of other variables

Page 19: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

19

Forward CheckingForward Checking After a variable X is assigned a value v,

look at each unassigned variable Y that is connected to X by a constraint and deletes from Y’s domain any value that is inconsistent with v

Page 20: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

20

Map ColoringMap Coloring

WA NT Q NSW V SA T

RGB RGB RGB RGB RGB RGB RGB

TWA

NT

SA

Q

NSW

V

Page 21: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

21

Map ColoringMap Coloring

WA NT Q NSW V SA T

RGB RGB RGB RGB RGB RGB RGB

R GB RGB RGB RGB GB RGB

TWA

NT

SA

Q

NSW

V

Page 22: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

22

WA NT Q NSW V SA T

RGB RGB RGB RGB RGB RGB RGB

R GB RGB RGB RGB GB RGB

R B G RB RGB B RGB

Map ColoringMap Coloring

TWA

NT

SA

Q

NSW

V

Page 23: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

23

Map ColoringMap Coloring

WA NT Q NSW V SA T

RGB RGB RGB RGB RGB RGB RGB

R GB RGB RGB RGB GB RGB

R B G RB RGB B RGB

R B G R B RGB

Impossible assignments that forward checking do not detect

TWA

NT

SA

Q

NSW

V

Page 24: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

24

Example: 4-Queens Problem

1

3

2

4

32 41

X1{1,2,3,4}

X3{1,2,3,4}

X4{1,2,3,4}

X2{1,2,3,4}

Page 25: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

25

Example: 4-Queens Problem

1

3

2

4

32 41

X1{1,2,3,4}

X3{1,2,3,4}

X4{1,2,3,4}

X2{1,2,3,4}

Page 26: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

26

Example: 4-Queens Problem

1

3

2

4

32 41

X1{1,2,3,4}

X3{ ,2, ,4}

X4{ ,2,3, }

X2{ , ,3,4}

Page 27: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

27

Example: 4-Queens Problem

1

3

2

4

32 41

X1{1,2,3,4}

X3{ ,2, ,4}

X4{ ,2,3, }

X2{ , ,3,4}

Page 28: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

28

Example: 4-Queens Problem

1

3

2

4

32 41

X1{1,2,3,4}

X3{ , , , }

X4{ ,2,3, }

X2{ , ,3,4}

Page 29: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

29

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1,2,3,4}

X4{1,2,3,4}

X2{1,2,3,4}

BTBT

Page 30: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

30

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1, ,3, }

X4{1, ,3,4}

X2{ , , ,4}

BTBT

Page 31: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

31

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1, ,3, }

X4{1, ,3,4}

X2{ , , ,4}

BTBT

Page 32: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

32

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1, , , }

X4{1, ,3, }

X2{ , , ,4}

BTBT

Page 33: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

33

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1, , , }

X4{1, ,3, }

X2{ , , ,4}

BTBT

Page 34: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

34

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1, , , }

X4{ , ,3, }

X2{ , , ,4}

BTBT

Page 35: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

35

Example: 4-Queens Problem

1

3

2

4

32 41

X1{ ,2,3,4}

X3{1, , , }

X4{ , ,3, }

X2{ , , ,4}

BTBT

Page 36: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

36

Edge Labeling Edge Labeling in Computer in Computer VisionVision

Page 37: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

37

Trihedral Objects

Objects in which exactly three plane surfaces come together at each vertex. Goal: label a 2-D object to produce a 3-D object

Page 38: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

38

Labels of Edges

Convex edge: two surfaces intersecting at an angle greater than

180°

Concave edge two surfaces intersecting at an angle less than 180°

+ convex edge, both surfaces visible− concave edge, both surfaces visible convex edge, only one surface is visible and it is on the right side of

Page 39: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

39

Junction Label SetsJunction Label Sets

+ + --

-- - + +

++ +

+

+

--

--

-+

(Waltz, 1975; Mackworth, 1977)

Page 40: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

40

Edge LabelingEdge Labeling

Page 41: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

41

Edge LabelingEdge Labeling

+

++

+

+

+

+

+

++

--

Page 42: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

42

Edge Labeling as a CSPEdge Labeling as a CSP

A variable is associated with each junctionThe domain of a variable is the label set of the corresponding junctionEach constraint imposes that the values given to two adjacent junctions give the same label to the joining edge

Page 43: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

43

Edge LabelingEdge Labeling

+ -

+

-+- -

++

Page 44: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

44

Edge LabelingEdge Labeling +

+

+

+---

-- -

+

Page 45: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

45

Edge LabelingEdge Labeling

+

+

+

++

+

-- - + +

++

Page 46: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

46

Edge LabelingEdge Labeling

++

+

- -++

+ + --

Page 47: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

47

Removal of Arc Removal of Arc InconsistenciesInconsistencies

REMOVE-ARC-INCONSISTENCIES(J,K)removed falseX label set of JY label set of KFor every label y in Y do If there exists no label x in X such that the

constraint (x,y) is satisfied then Remove y from Y If Y is empty then contradiction true removed true

Label set of K YReturn removed

Page 48: 1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations

48

CP Algorithm for Edge CP Algorithm for Edge LabelingLabeling

Associate with every junction its label set Q stack of all junctions while Q is not empty do J UNSTACK(Q) For every junction K adjacent to J do

If REMOVE-ARC-INCONSISTENCIES(J,K) then If K’s domain is non-empty then

STACK(K,Q) Else return false

(Waltz, 1975; Mackworth, 1977)