Constraint Satisfaction Problem Solving Chapter 5 Example problems
Constraint Satisfaction Problem Solving Chapter 5
Example problems Illustrative • Map coloring • Cryptarithmetic • N-queens Real • Class scheduling • Scheduled Hubble telescope • Discrete Optimization problems
Goal: solve the problem Find bindings for all the variables that satisfy all the constraints. Corresponds to boolean satisfiability, except that now variables take on values from discrete sets.
Formal Model • Finite set of variables: X 1, …Xn • Variable Xi has values in finite domain Di. • Constraints C 1…Cm. A constraint specifies legal combinations of the values. Tables. • Assignment: selection of values for all variables. • Consistent: assignment satisfies all constraints.
Note: Constraints can be made binary • Constraints = table of legal values • One trinary table between(a, b, c). – Between(2, 4, 5) • Replaced by conjunction of two binary relations – Less(2, 4) & Less(4, 5)
Simple Map colors: red, blue, green Goal: assign colors so touching countries have different colors C 1 C 3 C 2
Model • Variables X 1, X 2, X 3 • Domains Di = {red, blue, green}. • X 1 !=X 2 Table with 6 entries: red blue red green blue red blue green red green blue
Naïve Back. Tracking Solution • X 1 = red, X 2= red, X 3 = red, X 1!=X 2 #Fail – Short hand for table lookup (not in table) • X 1= red, X 2=red, X 3=blue, X 1!=X 2 #Fail • X 1= red, X 2=red, X 3=green…. Fail • X 1= red, X 2=blue, …. Continue to Solution. . UGH. But it is the way Prolog works.
Selections in Backtracking • Selecting a variable to bind • Selecting a value to assign to the variable Does Order Matter? • Yes and no • No: search is complete: any ordering will find a solution if one exists. • Yes: search cost changes.
Controlling Backtracking • Choosing a variable to bind – Minimum remaining values (MRV) – Intuition: need to solve eventually so do hardest case first • Degree Heuristic – choose variable involved in largest number of constraints. (tie-breaker) • Choosing a binding/value for variable – Least constraining variable – Intuition: maximize search options
Forward Checking • Constraint Propagation • If variable X is bound, find all variables Y that are connected to it by a constraint. Eliminate values that are inconsistent. • Can yield dramatic improvement. • Provably better than backtracking – Guaranteed to do less work
Relook at Map-coloring Using Forward Checking X 1= red: remove red from X 2 and X 3 domains X 2 = blue: remove blue from X 3’s domain X 3 = green. Done!
Arc-Consistency (3) • Binary CSP (can always force this) • Arc = edge between variables that are in same constraint. • Let X-Y be arc. – for each x in Domain X if there is no value y in domain Y that allows constraint to be met, then delete x from domain X. – Just look in the tables • Can be done as preprocessing or during search.
AC 3 Example • TWO+TWO = FOUR • edge between T and F gives: • (T+T+Carry )/10 = F we see that only T in {5, 6, 7, 8, 9} can work for F = 1. • Edge between F and R says R = 1. • Edge between (O+O)%10 = R and O=R gives: O = 0.
- Slides: 14