constraint satisfaction problems
play

Constraint Satisfaction Problems Chapter 6 Constraint Satisfaction - PowerPoint PPT Presentation

Constraint Satisfaction Problems Chapter 6 Constraint Satisfaction Problems A constraint satisfaction problem consists of three components, X, D, and C: X is a set of variables, {X 1 , . . . , X n }. D is a set of domains, {D 1 , . .


  1. Constraint Satisfaction Problems Chapter 6

  2. Constraint Satisfaction Problems ● A constraint satisfaction problem consists of three components, X, D, and C: ● X is a set of variables, {X 1 , . . . , X n }. ● D is a set of domains, {D 1 , . . . , D n }, one for each variable. ● C is a set of constraints that specify allowable combinations of values. ● Each constraint C i consists of a pair <scope, rel> where scope is a tuple of variables that participate in the constraint and rel is a relation that defines the values that those variables can take on. ● Example: if X 1 and X 2 both have the domain {A,B}, then the constraint saying the two variables must have different values can be written as ● <(X1 , X2 ), [(A, B), (B, A)]> ● <(X1 , X2 ), X1 ≠ X2 >

  3. Constraint Satisfaction Problems State and Solution ● Each state in a CSP is defined by an assignment of values to some or all of the variables, ● {X i = v i , X j = v j , . . .} ● An assignment that does not violate any constraints is called a consistent or legal assignment . ● A complete assignment is one in which every variable is assigned. ● a solution to a CSP is a consistent, complete assignment. ● A partial assignment is one that assigns values to only some of the variables.

  4. Example problem Map coloring ● We are given the task of coloring each region in a given map either red, green, or blue in such a way that no neighboring regions have the same color.

  5. Example problem Formulate as CSP ● X = {WA, NT ,Q, NSW, V, SA, T} ● D i = {red , green, blue} ● C = {SA ≠ WA, SA ≠ NT , SA ≠ Q, SA ≠ NSW , SA ≠ V, WA ≠ NT , NT ≠ Q, Q ≠ NSW , NSW ≠ V} SA ≠ WA is a shortcut for <(SA, WA), SA ≠ WA>

  6. Example problem Solution ● There are many possible solutions to this problem, such as {WA = red , NT = green, Q = red , NSW = green, V = red , SA = blue, T = green}

  7. Example problem Constraint Graph ● It can be helpful to visualize a CSP as a constraint graph. ● The nodes of the graph correspond to variables of the problem, and a link connects any two variables that participate in a constraint.

  8. Why CSP? ● Why formulate a problem as a CSP? ● the CSPs yield a natural representation for a wide variety of problems ● CSP solvers can be faster than state-space searchers because the CSP solver can quickly eliminate large swatches of the search space. ● many problems that are intractable for regular state-space search can be solved quickly when formulated as a CSP. ➢ Search and inference instead of just search ➢ Focus on variables violate a constraint.

  9. Variations on the CSP formalism Variable types ● The simplest kind of CSP involves variables that have discrete, finite domains (example: Map-coloring problems and n-queens) ● A discrete domain can be infinite, such as the set of integers or strings. ➔ A constraint language is needed to show constraints (example: T 1 + d 1 ≤ T 2 ) ● Constraint satisfaction problems with continuous domains are common in the real world. ➔ The best-known category of continuous-domain CSPs is that of linear programming problems, where constraints must be linear equalities or inequalities. ➔ Linear programming problems can be solved in time polynomial in the number of variables.

  10. Variations on the CSP formalism Constraint types ● The simplest type is the unary constraint , which restricts the value of a single variable: ➔ <(SA), SA ≠ green> ● A binary constraint relates two variables: ➔ <(SA, NSW), SA ≠ NSW> ➔ A binary CSP is one with only binary constraints; it can be represented as a constraint graph. ● A constraint involving an arbitrary number of variables is called a global constraint : ● One of the most common global constraints is Alldiff. ● Many real-world CSPs include preference constraints indicating which solutions are preferred: constraint optimization problem .

  11. Convert n-ary constraint to binary one ● Example: How a single ternary constraint such as “A + B = C” can be turned into three binary constraints? ● Using an auxiliary variable: First introduce a new variable AB and its domain. Then create appropriate relations between the new variables and old ones. B A A C AB B C

  12. Convert n-ary constraint to binary one Dual problem ● The dual problem is a reformulation of a constraint satisfaction problem expressing each constraint of the original problem as a variable and contains only binary constraints .

  13. Convert n-ary constraint to binary one Dual problem

  14. Convert n-ary constraint to binary one Dual problem

  15. Convert n-ary constraint to binary one Dual problem

  16. Inference in CSP ● In regular state-space search, an algorithm can do only one thing: search. ● In CSPs there is a choice: an algorithm can search (choose a new variable assignment from several possibilities) or do a specific type of inference called constraint propagation : ➢ using the constraints to reduce the number of legal values for a variable, which in turn can reduce the legal values for another variable, and so on: Local consistency . ➢ May be intertwined with search or may be done as a preprocessing step.

  17. Local Consistency ➔ Node consistency ➔ Arc consistency ➔ Path consistency ➔ k-consistency

  18. Local Consistency Node consistency ● A single variable is node-consistent if all the values in the variable’s domain satisfy the variable’s unary constraints. ● A network is node-consistent if every variable in the network is node-consistent. ● It can be done as a preprocessing step: eliminate all inconsistent values from variables' domains. ● It is always possible to eliminate all the unary constraints in a CSP by running node consistency. It is also possible to transform all n-ary constraints into binary ones. Because of this: It is common to define CSP solvers that work with only binary constraints.

  19. Local Consistency Arc consistency ● A variable in a CSP is arc-consistent if every value in its domain satisfies the variable’s binary constraints. ● More formally: X i is arc-consistent with respect to another variable X j if for every value in the current domain D i there is some value in the domain D j that satisfies the binary constraint on the arc (X i , X j ). ● A network is arc-consistent if every variable is arc consistent with every other variable. ● The most popular algorithm for arc consistency is called AC-3.

  20. Local Consistency Arc consistency (AC-3)

  21. Local Consistency Arc consistency (AC-3) ● Complexity = O(c*d*d 2 ) Complexity of revise function. Number of constraints Max size of domains: Max number of adding again a constraint To the queue.

  22. Local Consistency Generalized arc consistency ● A variable X i is generalized arc consistent with respect to an n- ary constraint if for every value v in the domain of X i there exists a tuple of values that is a member of the constraint, has all its values taken from the domains of the corresponding variables, and has its X i component equal to v. ● For example, if all variables have the domain {0, 1, 2, 3}, then to make the variable X consistent with the constraint X < Y < Z, we would have to eliminate 2 and 3 from the domain of X...

  23. Local Consistency Path consistency ● For many kind of problems, arc consistency fails to make enough inferences. Consider the map-coloring problem on Australia, but with only two colors allowed, red and blue...

  24. Local Consistency Path consistency ● A two-variable set {X i , X j } is path-consistent with respect to a third variable X m if, for every assignment {X i = a, X j = b} consistent with the constraints on {X i , X j }, there is an assignment to X m that satisfies the constraints on {X i , X m } and {X m , X j }. ● This is called path consistency because one can think of it as looking at a path from X i to X j with X m in the middle.

  25. Local Consistency Path consistency (Example) ● We will make the set {WA, SA} path consistent with respect to NT . ● We start by enumerating the consistent assignments to the set. In this case, there are only two: {WA = red , SA = blue} and {WA = blue, SA = red}. ● We can see that with both of these assignments NT can be neither red nor blue. ● We eliminate both assignments, and we end up with no valid assignments for {WA, SA}.

  26. Local Consistency k-consistency ● A CSP is k-consistent if, for any set of k − 1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any k th variable. ➢ 1-consistency: Node consistency. ➢ 2-consistency: Arc consistency. ➢ 3-consistency: Path consistency. ● A CSP is strongly k-consistent if it is k-consistent and is also (k−1)-consistent, (k−2)-consistent, . . . all the way down to 1-consistent.

  27. Local Consistency Find a solution ● Suppose there is a CSP with n nodes and strongly n-consistent. Now a solution can be found in this way: ➔ Choose a consistent value for X 1 . ➔ It is guaranteed to be able to choose a value for X 2 because the graph is 2-consistent, for X 3 because it is 3-consistent, and so on. ● It is guaranteed to find a solution in time O(n 2 d): For each variable X i , the algorithm only searches through the d values in the domain to find a value consistent with X 1 , . . . , X i−1 . ● Any algorithm for establishing n-consistency must take time exponential in n in the worst case.

Recommend


More recommend