1 / 65

Course: Engineering Artificial Intelligence

Course: Engineering Artificial Intelligence. Dr. Radu Marinescu. Lecture 4. Today’s class. Constraint satisfaction problems (CSP). Sudoku. Variables: 81 slots Domains = {1,2,3,4,5,6,7,8,9} Constraints: 27 not-equal. Constraint propagation. 2 3 4 6. 2.

Download Presentation

Course: Engineering Artificial Intelligence

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. Course:Engineering Artificial Intelligence Dr. Radu Marinescu Lecture 4

  2. Today’s class • Constraint satisfaction problems (CSP)

  3. Sudoku • Variables: 81 slots • Domains = {1,2,3,4,5,6,7,8,9} • Constraints: • 27 not-equal Constraint propagation 2 34 6 2 Each row, column and major block must be alldifferent “Well posed” if it has unique solution: 27 constraints

  4. Sudoku Each row, column and major block must be alldifferent “Well posed” if it has unique solution: 27 constraints

  5. Constraint satisfaction problems • CSP • state – is defined by variable Xi with values from domain Di • goaltest – is a set of constraints specifying allowable combinations of values for subsets of variables • Applications for CSPs • Scheduling tasks (transportation, maintenance) • Robot planning tasks • Puzzles • Tail-Gate assignment (airports) • Radio-link frequency assignment (telecom) • …

  6. Example: map coloring • variables: WA, NT, Q, SA, NSW, V, T • domains: Di = {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)}

  7. Example: map coloring • Solutions are complete and consistent assignments • E.g., WA = red, NT = green, SA = blue, Q = red, NSW = green, V = red, T = green

  8. Constraint graph General class of problems: Binary CSP Unary constraint arc variable Vi with values in domain Di Binary constraint arc (Unary constraint just cut down domains) This diagram is called a constraint graph

  9. Constraint graph General class of problems: Binary CSP Unary constraint arc variable Vi with values in domain Di Binary constraint arc (Unary constraint just cut down domains) This diagram is called a constraint graph Basic problem: Find dj in Di for each Vi s.t. all constraints satisfied (finding consistent labeling for variables)

  10. N-Queens as CSP Classic “benchmark” problem Place N queens on an NxN chessboard so that none can attack the other Variables are board positions in NxN chessboard Domains Queen or blank Constraints Two positions on a line (vertical, horizontal, diagonal) cannot both be Q

  11. Scheduling as CSP activity Choose time for activities e.g., observations on Hubble telescope, or terms to take required classes time Variables are activities Domains sets of start times (or “chunks” of time) Constraints 1. Activities that use the same resource cannot overlap in time 2. Preconditions satisfied

  12. 3-SAT as CSP The original NP-complete problem Find values for Boolean variables A, B, C, … that satisfy the formula Variables clauses Domains Boolean variable assignments that make clauses true Constraints Clauses with shared Boolean variables must agree on value of variables

  13. Varieties of CSPs • Discrete variables • Finite domains • n variables, domain size d → O(dn) complete assignments • E.g., map coloring, n-queens, … • Infinite domains • Integers, strings • E.g., job scheduling (variables are start/end days of each job) • Continuous variables • Usually, the domain of the variables are real numbers

  14. Varieties of constraints • Unaryconstraints involve one variable • E.g., SA ≠ green • Binaryconstraints involve pairs of variables • E.g., SA ≠ WA • Higher-orderconstraints involve 3 or more variables • E.g., crypt-arithmetic column constraints (see next)

  15. Example: crypt-arithmetic puzzle Variables F T U O R W X1 X2 X3 Domains {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Constraints AllDiff(F, T, U, O, R, W) O + O = R + 10∙X1 X1 + W + W = U + 10∙X2 X2 + T + T = O + 10∙X3 X3 = F F ≠ 0 T ≠ 0

  16. Good news / Bad news • Good news – very general & interesting class problems • Bad news – includes NP-hard (intractable) problems So, good behavior is a function of domain not the formulation as a CSP

  17. CSP example Given 40 courses (8.01, 8.02, …, 6.840) and 10 terms (Fall 1, Spring 1, ,,, Spring 5). Find a legal schedule Constraints Pre-requisites Courses offered on limited terms Limited number of courses per term Avoid time conflicts Note: CSPs are not for expressing (soft) preferences, e.g. minimize difficulty, balance subject areas, etc

  18. Choice of variables & values VARIABLESDOMAINS Legal combinations of for example 4 courses (but this is huge set of values) A. Terms? B. Terms Slots? Courses offered during that term Subdivide terms into slots e.g. 4 of them (Fall 1,1) (Fall 1,2) (Fall 1,3) (Fall 1,3) C. Courses? Terms or term slots (Term slots allow expressing constraints on limited number of courses/term)

  19. Constraints Use courses as variables and term slots as values Term before For pairs of courses that must be ordered 6.001 6.034 Prerequisite > Term after Courses offered only in some terms > Filter domain Term not equal For pairs offered at same or overlapping times Avoid time conflicts> 6.001 6.034

  20. Solving CSPs • Solving CSPs involve some combination of: • Constraint propagation, to eliminate values that could not be part of any solution • Search, to explore valid assignments

  21. Constraint propagation (aka Arc Consistency) • Arc consistency eliminates values from domain of variable that can never be part of a consistent solution • Directed arc (Vi, Vj) is arc consistent if

  22. Constraint propagation (aka Arc Consistency) • Arc consistency eliminates values from domain of variable that can never be part of a consistent solution • Directed arc (Vi, Vj) is arc consistent if • We can achieve consistency on arc by deleting values from Di (domain of variable at tail of constraint arc) that fail condition

  23. Constraint propagation (aka Arc Consistency) • Arc consistency eliminates values from domain of variable that can never be part of a consistent solution • Directed arc (Vi, Vj) is arc consistent if • We can achieve consistency on arc by deleting values from Di (domain of variable at tail of constraint arc) that fail condition • Assume domain size at most d and there are e binary constraints • A simple algorithm for arc consistency is O(ed3) – note that just verifying arc consistency takes O(ed2) for each arc

  24. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G

  25. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 R, G, B V2 V3 R, G G Each undirected arc is really two directed constraint arcs, the effects shown above are from examining BOTH arcs.

  26. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 R, G, B V2 V3 R, G G Each undirected arc is really two directed constraint arcs, the effects shown above are from examining BOTH arcs.

  27. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 R, B V2 V3 R, G G Each undirected arc is really two directed constraint arcs, the effects shown above are from examining BOTH arcs.

  28. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 R, B V2 V3 R G Each undirected arc is really two directed constraint arcs, the effects shown above are from examining BOTH arcs.

  29. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 B V2 V3 R G Each undirected arc is really two directed constraint arcs, the effects shown above are from examining BOTH arcs.

  30. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 B V2 V3 R G Each undirected arc is really two directed constraint arcs, the effects shown above are from examining BOTH arcs.

  31. Constraint propagation example V1 Graph coloring initial domains are indicated R, G, B different-color constraint V2 V3 R, G G V1 B V2 V3 R G CSP is arc-consistent

  32. But, arc consistency is not enough in general Graph coloring R, G arc consistent but no solutions R, G R, G

  33. But, arc consistency is not enough in general Graph coloring R, G arc consistent but no solutions R, G R, G arc consistent but 2 solutions: B,R,G; B,G,R B, G R, G R, G

  34. But, arc consistency is not enough in general Graph coloring R, G arc consistent but no solutions R, G R, G arc consistent but 2 solutions: B,R,G; B,G,R B, G R, G R, G arc consistent but 1 solutions: B,R,G; B, G Assume B, R not allowed R, G R, G

  35. But, arc consistency is not enough in general Graph coloring R, G arc consistent but no solutions R, G R, G arc consistent but 2 solutions: B,R,G; B,G,R B, G R, G R, G Need to search to find solutions (if any) arc consistent but 1 solutions: B,R,G; B, G Assume B, R not allowed R, G R, G

  36. Searching for solutions – backtracking (BT) • Standard search formulation • Initial state: the empty assignment {} • Successor function: assign a value to an unassigned variable that does not conflict with the current assignment • fail is no legal assignments • Goal test: the current assignment is complete • This is the same for all CSPs • Every solution appears at depth n (for n variables) • Path is irrelevant • Depth-first search for CSPs is called backtracking • Variable assignments are commutative (e.g., [WA=red then NT=blue] is the same as [NT=blue then WA=red]

  37. Searching for solutions – backtracking (BT) When we have too many values in domain (and/or constraints are weak) arc consistency doesn’t do much, so we need to search. Simplest approach is pure backtracking (depth-first search) R B V1assignments G R G V2assignments R G R G V3assignments R G R G R G R G V1 R, G,B V3 V2 R, G R, G

  38. Searching for solutions – backtracking (BT) When we have too many values in domain (and/or constraints are weak) arc consistency doesn’t do much, so we need to search. Simplest approach is pure backtracking (depth-first search) R B V1assignments G R G V2assignments R G R G V3assignments R G R G R G R G Inconsistent with V1 = R V1 R, G,B Backup at inconsistent assignment V3 V2 R, G R, G

  39. Searching for solutions – backtracking (BT) When we have too many values in domain (and/or constraints are weak) arc consistency doesn’t do much, so we need to search. Simplest approach is pure backtracking (depth-first search) R B V1assignments G R G V2assignments R G R G V3assignments R G R G R G R G Inconsistent with V1 = R V1 R, G,B Backup at inconsistent assignment V3 V2 R, G R, G

  40. Searching for solutions – backtracking (BT) When we have too many values in domain (and/or constraints are weak) arc consistency doesn’t do much, so we need to search. Simplest approach is pure backtracking (depth-first search) R B V1assignments G R G V2assignments R G R G V3assignments R G R G R G R G Inconsistent with V1 = R Inconsistent with V2 = G V1 R, G,B Backup at inconsistent assignment V3 V2 R, G R, G

  41. Searching for solutions – backtracking (BT) When we have too many values in domain (and/or constraints are weak) arc consistency doesn’t do much, so we need to search. Simplest approach is pure backtracking (depth-first search) R B V1assignments G R G V2assignments R G R G V3assignments R G R G R G R G consistent Inconsistent with V1 = R Inconsistent with V2 = G V1 R, G,B Backup at inconsistent assignment V3 V2 R, G R, G

  42. Combine backtracking and constraint propagation • A node in BT tree is partial assignment in which the domain of each variable has been set (tentatively) to singleton set • Use constraint propagation (arc-consistency) to propagate the effect of this tentative assignment i.e., eliminate values inconsistent with current values

  43. Combine backtracking and constraint propagation • A node in BT tree is partial assignment in which the domain of each variable has been set (tentatively) to singleton set • Use constraint propagation (arc-consistency) to propagate the effect of this tentative assignment i.e., eliminate values inconsistent with current values • Question: how much propagation to do?

  44. Combine backtracking and constraint propagation • A node in BT tree is partial assignment in which the domain of each variable has been set (tentatively) to singleton set • Use constraint propagation (arc-consistency) to propagate the effect of this tentative assignment i.e., eliminate values inconsistent with current values • Question: how much propagation to do? • Answer: not much, just local propagations from domains with unique assignments, which is called forward checking (FC). This conclusion is not necessarily obvious, but it generally holds in practice

  45. Backtracking with forward checking (BT-FC) When examining assignment Vi = dk, remove any values inconsistent with that assignment From neighboring domains in the constraint graph R V1assignments V2assignments V3assignments V1 R, G,B V3 V2 R, G R, G

  46. Backtracking with forward checking (BT-FC) When examining assignment Vi = dk, remove any values inconsistent with that assignment From neighboring domains in the constraint graph R V1assignments V2assignments G V3assignments V1 R V3 V2 G G

  47. Backtracking with forward checking (BT-FC) When examining assignment Vi = dk, remove any values inconsistent with that assignment From neighboring domains in the constraint graph R V1assignments V2assignments G V3assignments V1 R We have a conflict whenever a domain becomes empty V3 V2 G

  48. Backtracking with forward checking (BT-FC) When examining assignment Vi = dk, remove any values inconsistent with that assignment From neighboring domains in the constraint graph V1assignments G V2assignments V3assignments When backing up, need to restore domain values, since deletions were done to reach consistency with tentative assignments considered during search V1 R, G,B V3 V2 R, G R, G

  49. Backtracking with forward checking (BT-FC) When examining assignment Vi = dk, remove any values inconsistent with that assignment From neighboring domains in the constraint graph V1assignments G V2assignments V3assignments V1 G V3 V2 R R

  50. Backtracking with forward checking (BT-FC) When examining assignment Vi = dk, remove any values inconsistent with that assignment From neighboring domains in the constraint graph V1assignments G R V2assignments V3assignments V1 G V3 V2 R R

More Related