1 / 97

Lecture 6: Constraint Satisfaction Problems

CS461: Artificial Intelligence. Lecture 6: Constraint Satisfaction Problems. Outline. Constraint Satisfaction Problems (CSP) Backtracking search for CSPs Local search for CSPs. Constraint satisfaction problems (CSPs). Standard search problem

Download Presentation

Lecture 6: Constraint Satisfaction Problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS461: Artificial Intelligence Computer Science Department Lecture 6: Constraint Satisfaction Problems

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

  3. Constraint satisfaction problems (CSPs) • Standard search problem • state is a "black box“ – any data structure that supports successor function, heuristic function, and goal test • CSP: • state is defined by variablesXi with values from domainDi • goal test is a set of constraints specifying allowable combinations of values for subsets of variables • Simple example of a formal representation language • Allows useful general-purpose algorithms with more power than standard search algorithms Computer Science Department

  4. Example: Map-Coloring • VariablesWA, NT, Q, NSW, V, SA, T • DomainsDi = {red,green,blue} • Constraints: adjacent regions must have different colors • e.g., WA ≠ NT, or (WA,NT) in {(red,green),(red,blue),(green,red), (green,blue),(blue,red),(blue,green)} Computer Science Department

  5. Example: Map-Coloring • Solutions are complete and consistent assignments, e.g., WA = red, NT = green,Q = red,NSW = green,V = red,SA = blue,T = green Computer Science Department

  6. Constraint graph • Binary CSP: each constraint relates two variables • Constraint graph: nodes are variables, arcs are constraints Computer Science Department

  7. Varieties of CSPs • Discrete variables • finite domains: • n variables, domain size d  O(dn) complete assignments • e.g., Boolean CSPs, incl.~Boolean satisfiability (NP-complete) • infinite domains: • integers, strings, etc. • e.g., job scheduling, variables are start/end days for each job • need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3 • Continuous variables • e.g., start/end times for Hubble Space Telescope observations • linear constraints solvable in polynomial time by linear programming Computer Science Department

  8. Varieties of constraints • Unary constraints involve a single variable, • e.g., SA ≠ green • Binary constraints involve pairs of variables, • e.g., SA ≠ WA • Higher-order constraints involve 3 or more variables, • e.g., cryptarithmetic column constraints Computer Science Department

  9. Real-world CSPs • Assignment problems • e.g., who teaches what class • Timetabling problems • e.g., which class is offered when and where? • Transportation scheduling • Factory scheduling • Notice that many real-world problems involve real-valued variables Computer Science Department

  10. Standard search formulation (incremental) Let's start with the straightforward approach, then fix it States are defined by the values assigned so far • Initial state: the empty assignment { } • Successor function: assign a value to an unassigned variable that does not conflict with current assignment  fail if no legal assignments • Goal test: the current assignment is complete • This is the same for all CSPs • Every solution appears at depth n with n variables use depth-first search • Path is irrelevant, so can also use complete-state formulation • b = (n - l )d at depth l, hence n! · dn leaves Computer Science Department

  11. NxD WA WA WA NT T [NxD]x[(N-1)xD] WA NT WA NT WA NT NT WA Standard search formulation N layers Equal! N! x DN There are N! x DN nodes in the tree but only DN distinct states?? Computer Science Department

  12. 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 • 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 Computer Science Department

  13. D WA WA WA WA NT D2 WA NT WA NT DN Backtracking search Computer Science Department

  14. function BACKTRACKING-SEARCH (csp) returns a solution, or failure return RECURSIVE-BACKTRACKING({}, csp) function RECURSIVE-BACKTRACKING(assignment, csp) returns a solution, or failure ifassignment is complete then returnassignment var SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp], assignment, csp) for eachvalue in ORDER-DOMAIN-VALUES(var, assignment, csp) do ifvalue is consistent with assignment according to CONSTRAINTS[csp] then add {var=value} to assignment result RECURSIVE-BACKTRACKING(assignment, csp) ifresult != failurethen returnresult remove {var = value} from assignment return failure ☜ BACKTRACKING OCCURS HERE!! Backtracking search Computer Science Department

  15. Backtracking example Computer Science Department

  16. Backtracking example Computer Science Department

  17. Backtracking example Computer Science Department

  18. Backtracking example Computer Science Department

  19. 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? Computer Science Department

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

  21. BackpropagationMRVminimum remaining values • choose the variable with the fewest legal values Computer Science Department

  22. Backpropagation - MRV [R,B,G] [R,B,G] [R] [R,B,G] [R,B,G] Computer Science Department

  23. Backpropagation - MRV [R,B,G] [R,B,G] [R] [R,B,G] [R,B,G] Computer Science Department

  24. Backpropagation - MRV [R,B,G] [R,B,G] [R] [R,B,G] [R,B,G] Computer Science Department

  25. Backpropagation - MRV [R,B,G] [R,B,G] [R] [R,B,G] [R,B,G] Computer Science Department

  26. Backpropagation - MRV [R,B,G] [R,B,G] [R] [R,B,G] [R,B,G] Computer Science Department

  27. Backpropagation - MRV [R,B,G] [R,B,G] [R] [R,B,G] [R,B,G] Solution !!! Computer Science Department

  28. Most constraining variable • Tie-breaker among most constrained variables • Most constraining variable: • choose the variable with the most constraints on remaining variables (most edges in graph) Computer Science Department

  29. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  30. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  31. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  32. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  33. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs Dead End 3 arcs [R,B,G] [R,B,G] Computer Science Department

  34. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  35. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  36. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  37. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs Dead End 3 arcs [R,B,G] [R,B,G] Computer Science Department

  38. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  39. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  40. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  41. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  42. Backpropagation - MCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Solution !!! Computer Science Department

  43. 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 Computer Science Department

  44. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  45. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  46. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  47. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  48. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

  49. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Dead End Computer Science Department

  50. Back-propagation LCV [R,B,G] [R,B,G] 4 arcs 2 arcs 2 arcs [R] 3 arcs 3 arcs [R,B,G] [R,B,G] Computer Science Department

More Related