33
CONSTRAINT SATISFACTION The problem is defined through a set of variables and a set of domains variables can have possible values specified by the problem constraints describe allowable combinations of values for a subset of the variables State in a CSP defined by an assignment of values to some or all variables Solution to a CSP must assign values to all variables must satisfy all constraints 1

Constraint Satisfaction

  • Upload
    oriana

  • View
    33

  • Download
    0

Embed Size (px)

DESCRIPTION

Constraint Satisfaction. The problem is defined through a set of variables and a set of domains variables can have possible values specified by the problem constraints describe allowable combinations of values for a subset of the variables State in a CSP - PowerPoint PPT Presentation

Citation preview

Page 1: Constraint Satisfaction

CONSTRAINT SATISFACTION

The problem is defined through a set of variables and a set of domains variables can have possible values specified by the problem constraints describe allowable combinations of values for a

subset of the variables

State in a CSP defined by an assignment of values to some or all variables

Solution to a CSP must assign values to all variables must satisfy all constraints

1

Page 2: Constraint Satisfaction

CSP APPROACH

The goal test is decomposed into a set of constraints on variables

checks for violation of constraints before new nodes are generated must backtrack if constraints are violated

forward-checking looks ahead to detect unsolvability based on the current values of constraint variables

2

Page 3: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING

Color a map with three colors so that adjacent countries have different colors

G

FE

D

C

B

Avariables: A, B, C, D, E, F, G

values: {red, green, blue}

constraints: “no neighboring regions have the same color”

3

Page 4: Constraint Satisfaction

CONSTRAINT GRAPH

Visual representation of a CSP variables are nodes arcs are constraints

G

FED

C

B

A

the map coloring examplerepresented as constraint graph

4

Page 5: Constraint Satisfaction

SEND MORE MONEY - MODEL Variables

S, E, N, D, M, O, R, Y

Domain {0, …, 9}

Constraints

Distinct variables, S ≠ E, M ≠ S, …

S*1000 + E*100 + N*10 + D+M*1000 + O*100 + R*10 + E=M*10000 + O*1000 + N*100 + E*10 + Y

The solution to this puzzle is O = 0, M = 1, Y = 2, E = 5, N = 6, D = 7, R = 8, and S = 9.

S E N D + M O R E= M O N E Y

5

Page 6: Constraint Satisfaction

CSP AS INCREMENTAL SEARCH PROBLEM

Initial state all (or at least some) variables unassigned

Successor function assign a value to an unassigned variable must not conflict with previously assigned variables

Goal test all variables have values assigned no conflicts possible

not allowed in the successor function Path cost

e.g. a constant for each step may be problem-specific

6

Page 7: Constraint Satisfaction

BACKTRACKING SEARCH FOR CSPS

A variation of depth-first search that is often used for CSPs values are chosen for one variable at a time if no legal values are left, the algorithm backs up and

changes a previous assignment very easy to implement

initial state, successor function, goal test are standardized not very efficient

can be improved by trying to select more suitable unassigned variables first

7

Page 8: Constraint Satisfaction

HEURISTICS FOR CSP

Most-constrained variable (minimum remaining values, “fail-first”) variable with the fewest possible values is selected tends to minimize the branching factor

Most-constraining variable variable with the largest number of constraints on

other unassigned variables

Least-constraining value for a selected variable, choose the value that leaves

more freedom for future choices

8

Page 9: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING (CONT.)

Most-constrained-variable heuristic

G

FE

D

C

B

A

9

Page 10: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING (CONT.)

Most-constrained-variable heuristic

G

FE

D

C

B

A

10

Page 11: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING (CONT.)

Most-constrained-variable heuristic

G

FE

D

C

B

A

11

Page 12: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING (CONT.)

Most-constrained-variable heuristic

G

FE

D

C

B

A

12

Page 13: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING (CONT.)

Most-constrained-variable heuristic

G

FE

D

C

B

A

13

Page 14: Constraint Satisfaction

CSP EXAMPLE: MAP COLORING (CONT.)

Most-constrained-variable heuristic

G

FE

D

C

B

A

14

Page 15: Constraint Satisfaction

ANALYZING CONSTRAINTS

Forward checking when a value X is assigned to a variable, inconsistent

values are eliminated for all variables connected to X identifies “dead” branches of the tree before they are

visited

15

Page 16: Constraint Satisfaction

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}

16

Page 17: Constraint Satisfaction

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}

17

Page 18: Constraint Satisfaction

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}

18

Page 19: Constraint Satisfaction

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}

19

Page 20: Constraint Satisfaction

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}

20

Page 21: Constraint Satisfaction

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}

Backtra

cking

21

Page 22: Constraint Satisfaction

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}

22

Page 23: Constraint Satisfaction

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}

23

Page 24: Constraint Satisfaction

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}

24

Page 25: Constraint Satisfaction

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}

25

Page 26: Constraint Satisfaction

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}

26

Page 27: Constraint Satisfaction

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}

27

Page 28: Constraint Satisfaction

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}

28

Page 29: Constraint Satisfaction

LOCAL SEARCH AND CSP

Local search (iterative improvement) is frequently used for constraint satisfaction problems values are assigned to all variables modification operators move the configuration towards a

solution

Often called heuristic repair methods repair inconsistencies in the current configuration

Simple strategy: min-conflicts minimizes the number of conflicts with other variables solves many problems very quickly

29

Page 30: Constraint Satisfaction

8-QUEENS WITH MIN-CONFLICTS

One queen in each column usually several conflicts

Calculate the number of conflicts for each possible position of a selected queen

Move the queen to the position with the least conflicts

30

Page 31: Constraint Satisfaction

8-QUEENS EXAMPLE

12213221

222

3231

1

31

Page 32: Constraint Satisfaction

8-QUEENS EXAMPLE

1323

212

1

2330211

1

32

Page 33: Constraint Satisfaction

8-QUEENS EXAMPLE

Solution found in 4 steps Min-conflicts heuristic Uses additional

heuristics to select the “best” queen to move try to move out of the

corners similar to least-constraining

value heuristics