Unformatted text preview: Constraint Satisfaction
CMPSCI 383 September 18, 2008 1
1 Today’s lecture • Defining and representing constraint satisfaction problems (CSPs) • CSPs as search • Being smart about search in CSPs
• Variable and value ordering • Propagating information through constraints • Intelligent backtracking 2
2 What is constraint satisfaction?
• A family of methods for solving problems where the internal structure of solutions must satisfy a set of specified constraints • constraint satisfaction is the process of finding a solution to a set of constraints that impose conditions that the variables must satisfy • Variable and value ordering Choose next states wisely • Propagate information Provide good information to your heuristics • Intelligent backtracking Backtrack in a smart way
3
3 • Big ideas Have you done constraint satisfaction? 4
4 Have you done constraint satisfaction? 4
4 Have you done constraint satisfaction? 4
4 Have you done constraint satisfaction? 4
4 AI
5
5 CSP terminology 6
6 CSP terminology
• These entities are one part of the definition of a CSP, and they define candidate solutions 6
6 CSP terminology
• These entities are one part of the definition of a CSP, and they define candidate solutions • What are Variables 6
6 CSP terminology
• These entities are one part of the definition of a CSP, and they define candidate solutions • These entities define the possible set of values that variables can take on • What are Variables 6
6 CSP terminology
• These entities are one part of the definition of a CSP, and they define candidate solutions • These entities define the possible set of values that variables can take on • What are Variables • What are Domains 6
6 CSP terminology
• These entities are one part of the definition of a CSP, and they define candidate solutions • These entities define the possible set of values that variables can take on • These entities are the other part of the definition of a CSP, and they define limitations to possible assignments • What are Variables • What are Domains 6
6 CSP terminology
• These entities are one part of the definition of a CSP, and they define candidate solutions • These entities define the possible set of values that variables can take on • These entities are the other part of the definition of a CSP, and they define limitations to possible assignments • What are Variables • What are Domains • What are Constraints
6
6 What defines a CSP?
• In the general formulation of search, states are “black boxes” without internal structure • In CSPs, states are defined by assignments of values to a set of variables X1...Xn. Each variable Xi has a domain Di of possible values. • States are evaluated based on their consistency with a set of constraints C1...Cm over the values of the variables. • A goal state is a complete assignment to all variables that satisfies all the constraints.
7
7 Example: Map coloring • • • Variables — WA, NT, Q, NSW, V, SA, T Domains — Di={red,green,blue} Constraints — adjacent regions must have different colors.
• E.g. WA ≠ NT (if the language allows this) • E.g. (WA,NT) ≠ {(red,green),(red,blue),(green,red),…} 8
8 Example: Map coloring • Solutions are assignments satisfying all constraints, e.g. {WA=red,NT=green,Q=red,NSW=green,V=red,SA=blue,T=green} 9
9 Constraint graph 10
10 Constraint graph 10
10 Example: Cryptharithmetic 11
11 Example: Cryptharithmetic 11
11 Example: Cryptharithmetic 11
11 The CMPSCI 383 Computer 12
12 Please clap… in unison 13
13 Pick a number between 1 and 4 14
14 Pick a number between 1 and 4 14
14 AI
15
15 CSP terminology 16
16 CSP terminology
• This type of constraint concerns the relative values of two variables 16
16 CSP terminology
• This type of constraint concerns the relative values of two variables • What is a Binary constraint 16
16 CSP terminology
• This type of constraint concerns the relative values of two variables • This type of constraint concerns only a single value • What is a Binary constraint 16
16 CSP terminology
• This type of constraint concerns the relative values of two variables • This type of constraint concerns only a single value • What is a Binary constraint • What is a Unary constraint 16
16 Is this a search problem? 17
17 Is this a search problem?
• What does the search tree look like?
• What are the states? • What is the successor function? • What is the branching factor? • What search method would you apply? 17
17 Is this a search problem?
• What does the search tree look like?
• What are the states? • What is the successor function? • What is the branching factor? • What search method would you apply? • What are some good heuristics?
17
17 CSP solutions as search • Formulation is identical for all CSPs • Solution found at depth n (for n variables). • Path is irrelevant • Depth first search
• Branching factor b at the top level is nd. • b=(nl)d at depth l, hence n!dn leaves • …but only dn complete assignments 18
18 Commutativity • CSPs are commutative. • The order of any given set of actions has no effect on the outcome. • Example — choose colors for Australian territories one at a time
• [WA=red then NT=green] same as [NT=green then WA=red] • All CSP search algorithms consider a single variable assignment at a time ⇒ there are dn leaves.
19
19 Search example 20
20 Search example 21
21 Search example 22
22 Simple backtracking search • Depthfirst search • Choose values for one variable at a time • Backtrack when a variable has no legal values left to assign. • If search is uninformed, then general performance is relatively poor 23
23 How could we do better?
Think about our “classwide graph coloring” 24
24 Improving backtracking efficiency • Basic question: What next step should our search procedure take? • Approaches
• Minimum remaining values heuristic • Degree heuristic • Leastconstraining value heuristic 25
25 Minimum remaining values heuristic • Select the most constrained variable (the variable with the smallest number of remaining values) 26
26 Degree heuristic • Select the variable that is involved in the largest number of constraints with other unassigned variables • A useful tie breaker. • In what order should its values be tried?
27
27 Least constraining value
Allows 1 value for SA Allows 0 value for SA • Given a variable, choose the least constraining value — the value that leaves the maximum flexibility for subsequent variable assignments.
28
28 Propagating information through constraints • Basic question — Can we provide better information to our heuristics? • Forward checking
• Precomputing information needed by MRV • Early stopping • Constraint propagation
• Arc consistency (2consistency) • nconsistency 29
29 Forward checking • Can we detect inevitable failure early?
• And avoid it later? • Yes — track remaining legal values for unassigned variables • Terminate search when any variable has no legal values. 30
30 Forward checking • Assign {WA=red} • Effects on other variables connected by constraints with WA
• NT can no longer be red • SA can no longer be red
31
31 Forward checking • Assign {Q=green} • Effects on other variables connected by constraints with WA
• NT can no longer be green • NSW can no longer be green • SA can no longer be green
32
32 Forward checking • If V is assigned blue • Effects on other variables connected to WA
• SA is empty • NSW can no longer be blue • FC has detected a partial assignment that is inconsistent with the constraints. 33
33 Forward checking • • Solving CSPs with combination of heuristics plus forward checking is more efficient than either approach alone. FC checking propagates information from assigned to unassigned variables but does not provide detection for all failures.
• NT and SA cannot be blue! • Constraint propagation repeatedly enforces constraints locally
34
34 Arc consistency • X → Y is consistent iff for every value x of X there is some allowed y SA → NSW is consistent iff SA=blue and NSW=red • 35
35 Arc consistency • X → Y is consistent iff for every value x of X there is some allowed y NSW → SA is consistent iff NSW=red and SA=blue NSW=blue and SA=??? • Arc can be made consistent by removing blue from NSW 36
36 Arc consistency • • Arc can be made consistent by removing blue from NSW Recheck neighbours
• Remove red from V 37
37 Arc consistency • • Arc can be made consistent by removing blue from NSW Recheck neighbors
• Remove red from V • Arc consistency detects failure earlier than forward checking • Can be run as a preprocessor or after each assignment.
• Repeated until no inconsistency remains
38
38 nconsistency
• Arc consistency does not detect all inconsistencies:
• Partial assignment {WA=red, NSW=red} is inconsistent. • Stronger forms of propagation can be defined using the notion of nconsistency. • A CSP is nconsistent if for any set of n1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any nth variable.
• E.g. 1consistency or nodeconsistency • E.g. 2consistency or arcconsistency • E.g. 3consistency or pathconsistency
39
39 nconsistency
• Arc consistency does not detect all inconsistencies:
• Partial assignment {WA=red, NSW=red} is inconsistent. • Stronger forms of propagation can be defined using the notion of nconsistency. • A CSP is nconsistent if for any set of n1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any nth variable.
• E.g. 1consistency or nodeconsistency • E.g. 2consistency or arcconsistency • E.g. 3consistency or pathconsistency
40
40 nconsistency
• Arc consistency does not detect all inconsistencies:
• Partial assignment {WA=red, NSW=red} is inconsistent. • Stronger forms of propagation can be defined using the notion of nconsistency. • A CSP is nconsistent if for any set of n1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any nth variable.
• E.g. 1consistency or nodeconsistency • E.g. 2consistency or arcconsistency • E.g. 3consistency or pathconsistency
40
40 nconsistency
• Arc consistency does not detect all inconsistencies:
• Partial assignment {WA=red, NSW=red} is inconsistent. • Stronger forms of propagation can be defined using the notion of nconsistency. • A CSP is nconsistent if for any set of n1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any nth variable.
• E.g. 1consistency or nodeconsistency • E.g. 2consistency or arcconsistency • E.g. 3consistency or pathconsistency
40
40 nconsistency
• Arc consistency does not detect all inconsistencies:
• Partial assignment {WA=red, NSW=red} is inconsistent. • Stronger forms of propagation can be defined using the notion of nconsistency. • A CSP is nconsistent if for any set of n1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any nth variable.
• E.g. 1consistency or nodeconsistency • E.g. 2consistency or arcconsistency • E.g. 3consistency or pathconsistency
41
41 Further improvements
• Checking special constraints
• Checking Alldif(…) constraint
• E.g. {WA=red, NSW=red} • Checking Atmost(…) constraint
• Bounds propagation for larger value domains • Intelligent backtracking
• Standard form is chronological backtracking i.e. try different value for preceding variable. • More intelligent, backtrack to conflict set.
• Set of variables that caused the failure or set of previously assigned variables that are connected to X by constraints. • Backjumping moves back to most recent element of the conflict set. • Forward checking can be used to determine conflict set.
42
42 Is this a local search problem? 43
43 Is this a local search problem?
• Do we need the path to the solution or only the solution itself? 43
43 Is this a local search problem?
• Do we need the path to the solution or only the solution itself? • Is memory a constraint? 43
43 Is this a local search problem?
• Do we need the path to the solution or only the solution itself? • Is memory a constraint? • Can we apply local search methods?
• Hillclimbing • Simulated annealing • Genetic algorithms
43
43 What are good heuristics for choosing moves in local search when solving CSPs? 44
44 Minconflicts heuristic
• To enable local search
• allow states with unsatisfied constraints • operators reassign variable values • Variable selection: randomly select any conflicted variable • Value selection by minconflicts heuristic
• choose value that violates the fewest constraints • i.e., hillclimb with h(n) = total number of violated constraints 45
45 Example: 4Queens
• • • • States: 4 queens in 4 columns (44 = 256 states) Actions: move queen in column Goal test: no attacks; h(n) = 0 Evaluation: h(n) = number of attacks • Given random initial state, can solve nqueens in almost constant time for arbitrary n with high probability (e.g., n = 10,000,000) 46
46 Have you done local search to solve a CSP in this class? 47
47 Yes! 48
48 Yes! “Pick a number between 1 and 4” 48
48 Why can local search work well? 49
49 What’s hard about CSPs? 50
50 What’s hard about CSPs?
3color 4color *4color has sharper transition *4color has transition at higher connectivity
51
51 What’s hard about CSPs? 52
52 What’s hard about CSPs? Green : Underconstrained Region Pink : Overconstrained Region
53
53 Exploiting the structure of CSPs 54
54 Exploiting the structure of CSPs
• Decompose into independent problems 54
54 Exploiting the structure of CSPs
• Decompose into independent problems • Treestructured CSPs can be solved in linear time 54
54 Exploiting the structure of CSPs
• Decompose into independent problems • Treestructured CSPs can be solved in linear time • Reduce problems to treestructured CSPs 54
54 Exploiting the structure of CSPs
• Decompose into independent problems • Treestructured CSPs can be solved in linear time • Reduce problems to treestructured CSPs
• Cycle cutset conditioning — Remove nodes to create trees 54
54 Exploiting the structure of CSPs
• Decompose into independent problems • Treestructured CSPs can be solved in linear time • Reduce problems to treestructured CSPs
• Cycle cutset conditioning — Remove nodes to create trees • Tree decomposition — Decompose problem into a treestructured set of subproblems
54
54 Cycle cutset conditioning 55
55 Cycle cutset conditioning
• Want to create a tree 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? • Set value and restrict domains 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? • Set value and restrict domains • Does this always work well? 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? • Set value and restrict domains • Does this always work well?
• No, what can we do about that? 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? • Set value and restrict domains • Does this always work well?
• No, what can we do about that? • Step through possible settings 55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? • Set value and restrict domains • Does this always work well?
• No, what can we do about that? • Step through possible settings • What’s the payoff?
55
55 Cycle cutset conditioning
• Want to create a tree
• What is a tree? • Why do we want to create one? • Treestructured CSPs solvable in linear time • Create a tree by deleting nodes
• How can you delete nodes in CSPs? • Set value and restrict domains • Does this always work well?
• No, what can we do about that? • Step through possible settings • What’s the payoff?
• Big efficiency gains O(dc•(nc)d2)
55
55 Tree decomposition 56
56 Tree decomposition
• Again, want to create a tree 56
56 Tree decomposition
• Again, want to create a tree
• What’s another way of creating a tree? 56
56 Tree decomposition
• Again, want to create a tree
• What’s another way of creating a tree? • Merging nodes 56
56 Tree decomposition
• Again, want to create a tree
• What’s another way of creating a tree? • Merging nodes • What are the rules for doing this? 56
56 Tree decomposition
• Again, want to create a tree
• What’s another way of creating a tree? • Merging nodes • What are the rules for doing this?
• Every variable in ≥1 subproblems • All connected variable pairs, and assoc. constraints, in ≥1 subproblems • If a variable appears in 2 subproblems, it must appear in all subproblems on the path connecting the two subproblems
56
56 Tree decomposition
• Again, want to create a tree
• What’s another way of creating a tree? • Merging nodes • What are the rules for doing this?
• Every variable in ≥1 subproblems • All connected variable pairs, and assoc. constraints, in ≥1 subproblems • If a variable appears in 2 subproblems, it must appear in all subproblems on the path connecting the two subproblems • Now, how can we solve this new problem? 56
56 What are the big ideas for today? 57
57 ...
View
Full Document
 Fall '08
 STAFF
 Depthfirst search, NSW, Constraint satisfaction, Constraint satisfaction problem, treestructured csps, CSPs

Click to edit the document details