You are on page 1of 14

Introduction to

Constraint Satisfaction
Artificial Intelligence

1
Overview
 constraint satisfaction means solving a problem under certain constraints or
rules.
 CSP is a technique where a problem is solved when its values satisfy certain
constraints or rules of the problem. Such type of technique leads to a deeper
understanding of the problem structure as well as its complexity.
 A CSP consists of 3 components:
 ·X is a set of variables, {X1, …, Xn}.
 ·D is a set of domains, {D1, …, Dn}, one for each variable.
 Each domain Di consists of a set of allowable values, {v1, …, vk} for
variable Xi.
 ·C is a set of constraints that specify allowable combination of values.
 Each constraint Ci consists of 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.
2
 The requirements to solve a constraint satisfaction problem (CSP) is:
 A state-space
 The notion of the solution.
 A state in state-space is defined by assigning values to some or all variables
such as {X1=v1, X2=v2, and so on…}.
 A relation can be represented as: a. an explicit list of all tuples of values
that satisfy the constraint; or b. an abstract relation that supports two
operations. (e.g. if X1 and X2 both have the domain {A,B},
 The constraint saying “the two variables must have different values” can be
written as a. <(X1,X2),[(A,B),(B,A)]> or b. <(X1,X2),X1≠X2>.
 Examples
 N-queens problem
 Graph coloring problem
 Crossword puzzle, etc.
3 3
Solving Constraint Satisfaction Problems
The requirements to solve a constraint satisfaction problem (CSP) is:
A state-space
The notion of the solution.
A state in state-space is defined by assigning values to some or all variables
such as
{X1=v1, X2=v2, and so on…}.

Types of Domains in CSP


There are following two types of domains which are used by the variables :
Discrete Domain: It is an infinite domain which can have one state for multiple
variables. For example, a start state can be allocated infinite times for each
variable.
Finite Domain: It is a finite domain which can have continuous states describing
one domain for one specific variable. It is also called a continuous domain.

4
 Assignment:
 Each state in a CSP is defined by an assignment of
values to some of the variables, {Xi=vi, Xj=vj, …};
 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.

5
Constraint Types in CSP
 With respect to the variables, basically there are following types of constraints:
 Unary Constraints: It is the simplest type of constraints that restricts the value of a single
variable.
 Binary Constraints: It is the constraint type which relates two variables. A value x2 will
contain a value which lies between x1 and x3.
 Global Constraints: It is the constraint type which involves an arbitrary number of
variables.
 Some special types of solution algorithms are used to solve the following types of
constraints:
 Linear Constraints: These type of constraints are commonly used in linear programming
where each variable containing an integer value exists in linear form only.
 Non-linear Constraints: These type of constraints are used in non-linear programming
where each variable (an integer value) exists in a non-linear form.
 Note: A special constraint which works in real-world is known as Preference constraint.

6
7
To formulate a CSP:
define the variables to be the regions X = {WA, NT, Q,
NSW, V, SA, T}.
The domain of each variable is the set Di = {red, green,
blue}.
The constraints is C = {SA≠WA, SAW≠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>. )
Constraint graph: The nodes of the graph correspond
to variables of the problem, and a link connects to any
two variables that participate in a constraint.

8
Advantage of formulating a
problem as a CSP
1) CSPs yield a natural representation for a wide variety of
problems;
2) CSP solvers can be faster than state-space searchers
because the CSP solver can quickly eliminate large swatches of
the search space;
3) With CSP, once we find out that a partial assignment is not a
solution, we can immediately discard further refinements of the
partial assignment.
4) We can see why a assignment is not a solution—which
variables violate a constraint.

9
Three approaches to solve the CSP:

•Tree Search
•Constraints Propagation
•Combining Backtracking search and
Constraints Propagation
 Constraint propagation is a special type of inference which helps in
reducing the legal number of values for the variables. The idea
behind constraint propagation is local consistency.
 In local consistency, variables are treated as nodes, and each binary
constraint is treated as an arc in the given problem.
 Node Consistency: A single variable is said to be node consistent if
all the values in the variable’s domain satisfy the unary constraints on
the variables.
 Arc Consistency: A variable is arc consistent if every value in its
domain satisfies the binary constraints of the variables.
 Path Consistency: When the evaluation of a set of two variable with
respect to a third variable can be extended over another variable,
satisfying all the binary constraints. It is similar to arc consistency.
 k-consistency: This type of consistency is used to define the notion
of stronger forms of propagation. Here, we examine the k-consistency
of the variables. 11
• The general approach to solving a CSP is the generate-and-test
method.
• Each possible assignment of values to variables is systematically
generated and then tested to see if it satisfies all the constraints.
• The first assignment that satisfies all the constraints is the solution.
• In the worst-case (or when we are trying to find all the solutions for a
CSP, the number of assignments to be considered is the size of the
Cartesian product of all the variable domains.
• Thus, the time complexity of this approach is exponential in the
number of variables. Empirically this method performs very poorly.
• Randomized generate-and-test algorithms that select the
assignments to test at random in accord with some biased
distribution (e.g. the distribution might be biased by the most recently
tested assignments as in randomized hill-climbing) can sometimes
perform extremely well, but unfortunately, lose systematicity.
12
 Constraint satisfaction includes those problems
which contains some constraints while solving
the problem. CSP includes the following
problems:
 Graph Coloring: The problem where the
constraint is that no adjacent sides can have
the same color.

13
Thank you.

14

You might also like