constraint satisfaction problems
play

Constraint Satisfaction Problems Robert Platt Northeastern - PowerPoint PPT Presentation

Constraint Satisfaction Problems Robert Platt Northeastern University Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA Image: Berkeley CS188 course notes (downloaded Summer 2015) What is a CSP? CSPs All search problems


  1. Constraint Satisfaction Problems Robert Platt Northeastern University Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA Image: Berkeley CS188 course notes (downloaded Summer 2015)

  2. What is a CSP? CSPs All search problems The space of all search problems – states and actions are atomic – goals are arbitrary sets of states The space of all CSPs – states are defined in terms of variables – goals are defined in terms of constraints A CSP is defined by: 1. a set of variables and their associated domains 2. a set of constraints that must be satisfied.

  3. CSP example: map coloring Problem: assign each territory a color such that no two adjacent territories have the same color Variables: Domain of variables: Constraints:

  4. CSP example: n-queens Problem: place n queens on an nxn chessboard such that no two queens threaten each other Variables: Domain of variables: Constraints:

  5. CSP example: n-queens Problem: place n queens on an nxn chessboard such that no two queens threaten each other One variable for every square Variables: Domain of variables: Binary Constraints: Enumeration of each possible disallowed configuration – why is this a bad way to encode the problem?

  6. CSP example: n-queens Problem: place n queens on an nxn chessboard such that no two queens threaten each other One variable for every square Variables: Is there a better way? Domain of variables: Binary Constraints: Enumeration of each possible disallowed configuration – why is this a bad way to encode the problem?

  7. CSP example: n-queens 1 2 3 4 5 6 7 8 Problem: place n queens on an nxn chessboard such that no two queens threaten each other One variable for each row Variables: Domain of variables: A number between 1 and 8 Constraints: Enumeration of disallowed configurations – why is this representation better?

  8. The constraint graph Variables represented as nodes (i.e. as circles) Constraint relations represented as edges – map coloring is a binary CSP, so it's easier to represent...

  9. A harder CSP to represent: Cryptarithmetic  Variables:  Domains:  Constraints: Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  10. Another example: sudoku  Variables:  Each (open) square  Domains:  {1,2,…,9}  Constraints: 9-way alldifg for each column 9-way alldifg for each row 9-way alldifg for each region (or can have a bunch of pairwise inequality constraints) Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  11. Naive solution: apply BFS, DFS, A*, ... Which would be better: BFS, DFS, A*? – remember: it doesn't know if it reached a goal until all variables are assigned ...

  12. Naive solution: apply BFS, DFS, A*, ... _ _ _ _ _ _ _ R _ _ _ _ _ _ R G _ _ _ _ _ R G R _ _ _ _ ... ... R G R R R R R How many leaf nodes are expanded in the worst case?

  13. Naive solution: apply BFS, DFS, A*, ... _ _ _ _ _ _ _ R _ _ _ _ _ _ R G _ _ _ _ _ R G R _ _ _ _ ... ... R G R R R R R How many leaf nodes are expanded in the worst case?

  14. Naive solution: apply BFS, DFS, A*, ... _ _ _ _ _ _ _ R _ _ _ _ _ _ R G _ _ _ _ _ This sucks. R G R _ _ _ _ How can we improve it? ... ... R G R R R R R How many leaf nodes are expanded in the worst case?

  15. Backtracking search When a node is expanded, check that each successor state is consistent before adding it to the queue.

  16. Backtracking search When a node is expanded, check that each successor state is consistent before adding it to the queue. Does this state have any valid successors?

  17. Backtracking search – backtracking enables us the ability to solve a problem as big as 25-queens

  18. Forward checking Sometimes, failure is inevitable: Can we detect this situation in advance?

  19. Forward checking Sometimes, failure is inevitable: Can we detect this situation in advance? Yes: keep track of viable variable assignments as you go

  20. Forward checking Track domain for each unassigned variable – initialize w/ domains from problem statement – each time you expand a node, update domains of all unassigned variables

  21. Forward checking Track domain for each unassigned variable – initialize w/ domains from problem statement – each time you expand a node, update domains of all unassigned variables

  22. Forward checking Track domain for each unassigned variable – initialize w/ domains from problem statement – each time you expand a node, update domains of all unassigned variables

  23. Forward checking Track domain for each unassigned variable – initialize w/ domains from problem statement – each time you expand a node, update domains of all unassigned variables

  24. Forward checking But, failure was inevitable here! – what did we miss?

  25. Arc consistency  An arc X → Y is consistent ifg for every x in the tail there is some y in the head which could be assigned without violating a constraint NT Q WA SA NSW V Delete from the tail!  Forward checking: Enforcing consistency of arcs pointing to each new assignment Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  26. Arc consistency  An arc X → Y is consistent ifg for every x in the tail there is some y in the head which could be assigned without violating a constraint NT Q WA SA NSW V Delete from the tail!  Forward checking: Enforcing consistency of arcs pointing to each new assignment Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  27. Forward checking But, failure was inevitable here! – what did we miss?

  28. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Delete values from tail in order to make each arc consistent Consistent: for every value in the tail, there is some value in the head that could be assigned w/o violating a constraint. Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  29. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Delete values from tail in order to make each arc consistent Consistent: for every value in the tail, there is some value in the head that could be assigned w/o violating a constraint. Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  30. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Delete values from tail in order to make each arc consistent Consistent: for every value in the tail, there is some value in the head that could be assigned w/o violating a constraint. Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  31. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Delete values from tail in order to make each arc consistent Consistent: for every value in the tail, there is some value in the head that could be assigned w/o violating a constraint. Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  32. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Delete values from tail in order to make each arc consistent Consistent: for every value in the tail, there is some value in the head that could be assigned w/o violating a constraint. Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  33. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Conflict! Delete values from tail in order to make each arc consistent Consistent: for every value in the tail, there is some value in the head that could be assigned w/o violating a constraint. Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  34. Arc consistency  A simple form of propagation makes sure all arcs are consistent: NT Q WA SA NSW V Conflict!  Important: If X loses a value, neighbors of X need to be rechecked!  Arc consistency detects failure earlier than forward checking  Can be run as a preprocessor or after each assignment  What’s the downside of enforcing arc consistency? Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  35. Arc consistency Why does this algorithm converge?

  36. Arc consistency does not detect all inconsistencies...  After enforcing arc consistency:  Can have one solution left  Can have multiple solutions left  Can have no solutions left (and not know it) What went wrong here?  Arc consistency still runs inside a backtracking search! Slide: Berkeley CS188 course notes (downloaded Summer 2015)

  37. Heuristics for improving CSP performance Minimum remaining values (MRV) heuristic: – expand variables w/ minimum size domain first

  38. Heuristics for improving CSP performance Minimum remaining values (MRV) heuristic: – expand variables w/ minimum size domain first

  39. Heuristics for improving CSP performance Minimum remaining values (MRV) heuristic: – expand variables w/ minimum size domain first

  40. Heuristics for improving CSP performance Least constraining value (LCV) heuristic: – consider how domains of neighbors would change under A.C. – choose value that contrains neighboring domains the least

Recommend


More recommend