Constraint Satisfaction Problems - PowerPoint PPT Presentation

constraint satisfaction problems n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Constraint Satisfaction Problems PowerPoint Presentation
Download Presentation
Constraint Satisfaction Problems

play fullscreen
1 / 84
Constraint Satisfaction Problems
174 Views
Download Presentation
evonne
Download Presentation

Constraint Satisfaction Problems

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Constraint Satisfaction Problems Chapter 5

  2. Outline • Constraint Satisfaction Problems (CSP) • Backtracking search for CSPs • Local search for CSPs

  3. Intro Example: 8-Queens • Purely generate-and-test • The “search” tree is only used to enumerate all possible 648 combinations

  4. Intro Example: 8-Queens Another form of generate-and-test, with no redundancies  “only” 88 combinations

  5. Intro Example: 8-Queens

  6. What is Needed? • Not just a successor function and goal test • But also a means to propagate the constraints imposed by one queen on the others and an early failure test •  Explicit representation of constraints and constraint manipulation algorithms

  7. Constraint Satisfaction Problem • 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

  8. Constraint Satisfaction Problem • 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

  9. Example: 8-Queens Problem • 64 variables Xij, i = 1 to 8, j = 1 to 8 • Domain for each variable {yes,no} • Constraints are of the forms: • Xij = yes  Xik = no for all k = 1 to 8, kj • Xij = yes  Xkj = no for all k = 1 to 8, kI • Similar constraints for diagonals

  10. Example: 8-Queens Problem • 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, ji • Similar constraints for diagonals

  11. NT Q WA SA NT NSW Q V WA SA T NSW V T Example: 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: • WANT, WASA, NTSA, NTQ, SAQ, SANSW, SAV,QNSW, NSWV

  12. 2 3 4 1 5 Example: Street Puzzle Ni = {English, Spaniard, Japanese, Italian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Coffee, Milk, Fruit-juice, Water} Ji = {Painter, Sculptor, Diplomat, Violonist, Doctor} Ai = {Dog, Snails, Fox, Horse, Zebra}

  13. 2 3 4 1 5 Example: Street Puzzle Ni = {English, Spaniard, Japanese, Italian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Coffee, Milk, Fruit-juice, Water} Ji = {Painter, Sculptor, Diplomat, Violonist, Doctor} Ai = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violonist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s Who owns the Zebra? Who drinks Water?

  14. T1 T2 T4 T3 Example: Task Scheduling • T1 must be done during T3 • T2 must be achieved before T1 starts • T2 must overlap with T3 • T4 must start after T1 is complete • Are the constraints compatible? • Find the temporal relation between every two tasks

  15. Finite vs. Infinite CSP • Finite domains of values  finite CSP • Infinite domains  infinite CSP

  16. Finite vs. Infinite CSP • Finite domains of values  finite CSP • Infinite domains  infinite CSP • We will only consider finite CSP

  17. Binary constraints NT T1 Q WA T2 NSW T4 SA V T3 T Constraint Graph Two variables are adjacent or neighbors if they are connected by an edge or an arc

  18. CSP as a Search Problem • Initial state: empty assignment • Successor function: a value is assigned to any unassigned variable, which does not conflict with the currently assigned variables • Goal test: the assignment is complete • Path cost: irrelevant

  19. CSP as a Search Problem • Initial state: empty assignment • Successor function: a value is assigned to any unassigned variable, which does not conflict with the currently assigned variables • Goal test: the assignment is complete • Path cost: irrelevant n variables of domain size d O(dn) distinct complete assignments

  20. Remark • Finite CSP include 3SAT as a special case (see class of CS311) • 3SAT is known to be NP-complete • So, in the worst-case, we cannot expect to solve a finite CSP in less than exponential time

  21. Commutativity of CSP Generate successors of a node by considering assignments for only one variable Do not store the path to node

  22. empty assignment 1st variable 2nd variable 3rd variable Assignment = {}  Backtracking Search

  23. empty assignment 1st variable 2nd variable 3rd variable  Backtracking Search Assignment = {(var1=v11)}

  24. empty assignment 1st variable 2nd variable 3rd variable  Backtracking Search Assignment = {(var1=v11),(var2=v21)}

  25. empty assignment 1st variable 2nd variable 3rd variable  Backtracking Search Assignment = {(var1=v11),(var2=v21),(var3=v31)}

  26. empty assignment 1st variable 2nd variable 3rd variable  Backtracking Search Assignment = {(var1=v11),(var2=v21),(var3=v32)}

  27. empty assignment 1st variable 2nd variable 3rd variable  Backtracking Search Assignment = {(var1=v11),(var2=v22)}

  28. empty assignment 1st variable 2nd variable 3rd variable  Backtracking Search Assignment = {(var1=v11),(var2=v22),(var3=v31)}

  29. Backtracking search • Variable assignments are commutative}, i.e., [ WA = red then NT = green ] same as [ NT = green then WA = red ] • Only need to consider assignments to a single variable at each node  b = d and there are dn leaves • Depth-first search for CSPs with single-variable assignments is called backtracking search • Backtracking search is the basic uninformed algorithm for CSPs • Can solve n-queens for n ≈ 25

  30. Backtracking search

  31. Backtracking example

  32. Backtracking example

  33. Backtracking example

  34. Backtracking example

  35. Improving backtracking efficiency • General-purpose methods can give huge gains in speed: • Which variable should be assigned next? • In what order should its values be tried? • Can we detect inevitable failure early?

  36. Most constrained variable • Most constrained variable: choose the variable with the fewest legal values • a.k.a. minimum remaining values (MRV) heuristic

  37. Most constraining variable • Tie-breaker among most constrained variables • Most constraining variable: • choose the variable with the most constraints on remaining variables

  38. Least constraining value • Given a variable, choose the least constraining value: • the one that rules out the fewest values in the remaining variables • Combining these heuristics makes 1000 queens feasible

  39. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  40. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  41. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  42. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  43. Constraint propagation • Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures: • NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally

  44. Arc consistency algorithm AC-3 • Time complexity: O(n2d3)

  45. partial assignment of variables Backtracking Algorithm CSP-BACKTRACKING({}) CSP-BACKTRACKING(a) • If a is complete then return a • X select 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

  46. {} NT Q WA WA=red WA=green WA=blue SA NSW V WA=red NT=green WA=red NT=blue T WA=red NT=green Q=red WA=red NT=green Q=blue Map Coloring

  47. Questions • Which variable X should be assigned a value next? • In which order should its domain D be sorted?

  48. Questions • Which variable X should be assigned a value next? • In which order should its domain D be sorted? • What are the implications of a partial assignment for yet unassigned variables? ( Constraint Propagation)

  49. NT WA NT Q WA SA SA NSW V T Choice of Variable • Map coloring

  50. Choice of Variable • 8-queen