1 / 35

Constraint Satisfaction Problems

Constraint Satisfaction Problems. Introduction to AI. Real World Samples of CSP. Assignment problems e.g., who teaches what class Timetabling problems e.g., which class is offered when and where? Transportation scheduling Factory scheduling. Map Colouring. Given a map of “countries”:

eve
Télécharger la présentation

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. Constraint Satisfaction Problems Introduction to AI

  2. Real World Samples of CSP • Assignment problems • e.g., who teaches what class • Timetabling problems • e.g., which class is offered when and where? • Transportation scheduling • Factory scheduling

  3. Map Colouring • Given a map of “countries”: • Assign a colour to each country such that IF two countries share a border THEN they are given different colours • We can only use a limited number of colours • Alternatively, we must use the minimal possible number of colours

  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)}

  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

  6. Constraint Graph

  7. Map Colouring: Example • Consider some “square” countries: • How many colours are needed?

  8. Example: 3 colours? Take the 3 colours to be red, green, blue How would you be sure that you have not missed out some possible 3 colouring? Need some complete search method! NO COLOUR LEFT!

  9. Example: 4 colours? WITH JUST ONE MORE COLOUR IT IS POSSIBLE NO COLOUR LEFT!

  10. Motivations • Map Colouring is a specific problem • so why care? • Map Colouring is a typical “Constraint Satisfaction Problem (CSP)” • CSPs have many uses • scheduling • timetabling • window (task pane) manager in a GUI • and many other common optimization problems with industrial applications

  11. Constraint Satisfaction Problems Must be Hot&Sour Soup No Peanuts Chicken Dish Appetizer Total Cost < $30 No Peanuts Pork Dish Vegetable Seafood Rice Not Both Spicy Not Chow Mein Constraint Network

  12. Potential Follow-up “Constraint Programming” • A different programming paradigm • “you tell it what to solve, the system decides how to solve” • a program to solve Sudoku can be only 20 lines of code! • e.g. constraints on each row that all numbers in a row are different is just forall( j in 1..9 ) alldifferent( all(i in 1..9) pos[i,j] ); • Very different from the usual paradigms: • Procedural (Fortran, Pascal, C) • Object-Oriented (C++, Java, C#) • Functional (Lisp, ML, Haskell) • Commercialised by ILOG, www.ilog.com, and others

  13. From Maps to CSPs • Will convert the map colouring into general idea of a CSP: • Assign values • such that the assigned values satisfy some constraints

  14. B A C D E F Map Colouring • Firstly add some labels

  15. B A C D E F Map Colouring: Constraints • Graphs are more common than maps – so convert to a graph • Edge means “share a border”

  16. B A C D E F Graph 3-Colouring • Node, or “variable”, must be given a value from the set of colours { r, g , b } • E.g. B := b • Edge between two nodes  only allowed pairs of values from the set{ (r,g), (r,b), (g, r), (g, b), (b, r), (b, g) }

  17. Search Methods • If want a complete search method then it is standard to use depth-first search with partial assignments • Work with Partial Assignments • Start with the empty assignment • Generate children by adding a value for one more variable • Analogy: path-finding – we started with the empty path, and then added one more segment at each time • We already did this with the map colouring at the start of the lecture!

  18. CSPs vs. Standard Search Problems • 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

  19. Backtracking Example

  20. Backtracking Example

  21. Backtracking Example

  22. Backtracking Example

  23. Backtracking Search Animation • Nodes are not created until they are ready to be used – to reduce memory usage A 2nd child of A is not created immediately,just remember that it is there B E D C

  24. A B C Can we 2-colour a Triangle? • Can we assign values from { r , g } with the following variables and constraints? • Obviously not! • But how can we see this using search?

  25. name of node is just the branch variable Can we 2-colour a Triangle? • Can we assign values from { r , g } to nodes A, B, and C • “Generate-and-Test”: Colour nodes in the order, A, B, C A A=g A=r All the attempts to generate a satisfying assignment fail B B=r B=g Etc, etc C C C=r C=r C=g C=g Fail Fail Fail Fail

  26. Early Failure • Suppose a partial assignment fails i.e. violates a constraint • Whatever values we eventually give to the so-far un-assigned variables the constraint will stay violated, and the solution will fail • In the backtracking search: • as soon as a constraint is violated by the current partial assignment then we can prune the search

  27. Can we 2-colour a Triangle? • Naive Backtracking Search: • Backtracking with pruning of bad partial assignments A A=g A=r B B=r B=g C Fail C=r Did not have to try values for C C=g Fail Fail

  28. Varieties of constraints • Unary constraints involve a single variable, • e.g., SA ≠ green • Binary constraints involve pairs of variables, • e.g., value(SA) ≠ value(WA) • Higher-order constraints involve 3 or more variables, • e.g., cryptarithmetic column constraints

  29. Example: Latin Squares Puzzle X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 red RT RS RC RO green GT GS GC GO blue BT BS BC BO yellow YT YS YC YO Variables Values Constraints: In each row, each column, each major diagonal, there must be no two markers of the same color or same shape.

  30. 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

  31. Graph Matching Example Find a subgraph isomorphism from R to S. R 2 1 (1,a) (1,b) (1,c) (1,d) (1,e) 4 3 (2,a) (2,b) (2,c) (2,d) (2,e) X X X S e (3,a) (3,b) (3,c) (3,d) (3,e) (3,a) (3,b) (3,c) (3,d) (3,e) X X X X X X X X X a c (4,a) (4,b) (4,c) (4,d) (4,e) X X X X b d How do we formalize this problem?

  32. x 11 x x 12 1n x 2 21 a 2 b x 2 2 22 x 2n A Tiny Transportation problem • How much should be shipped from several sources to several destinations Demand Qty Supply cpty Source Qty Shipped Destination a 1 b 1 1 1 : : : : n a m b m n

  33. Constraint Satisfaction Problems Must be Hot&Sour Soup No Peanuts Chicken Dish Appetizer Total Cost < $30 No Peanuts Pork Dish Vegetable Seafood Rice Not Both Spicy Not Chow Mein Constraint Network

  34. Example: 4-Queens • States: 4 queens in 4 columns (44 = 256 states) • Actions: move queen in column • Goal test: no attacks • Evaluation: h(n) = number of attacks • Given random initial state, can solve n-queens in almost constant time for arbitrary n with high probability (e.g., n = 10,000,000)

  35. The path cost is shown by the number on the links; the heuristic evaluation is shown by the number in the box. Assume that S is the start state and G is the goal state. • (a) What is the order that breadth-first search will expand the nodes? • (b) What is the order that depth-first search will expand the nodes? • (c) What is the order that hill climbing search will expand the nodes? • (d) What is the order that A* search will expand the nodes?

More Related