AI Unit 2 CSP
AI Unit 2 CSP
SATISFACTION
PROBLEMS
COSTRAINT SATISFACTION PROBLEMS
Previous Search Problems:
• problems can be solved by searching in a space of states. These states can be evaluated by domain-specific
heuristics and tested to see whether they are goal states
• From the point of view of the search algorithm, however, each state is atomic, or indivisible—a black box with
no internal structure
CSP:
• CSP describes a way to solve a wide variety of problems more efficiently. We use a factored representation
for each state: a set of variables, each of which has a value
• Here, a problem is solved when each variable has a value that satisfies all the constraints on the variable
• CSP search algorithms take advantage of the structure of states and use general-purpose rather than problem-
specific heuristics to enable the solution of complex problems.
• The main idea is to eliminate large portions of the search space all at once by identifying variable/value
combinations that violate the constraints
DEFINING CONSTRAINT SATISFACTION PROBLEMS
A constraint satisfaction problem consists of three components, X, D, and C:
• D is a set of domains, {D1,... , Dn}. Each domain Di consists of a set of allowable values, {v1,... , vk} for
variable Xi
• A relation can be represented as an explicit list of all tuples of values that satisfy the constraint, or as an
abstract relation that supports two operations: testing if a tuple is a member of the relation and enumerating
the members of the relation.
SOLUTION
• To solve a CSP, we need to define a state space and the notion of a solution.
• An assignment that does not violate any constraints is called a consistent or legal
assignment.
• We are given the task of coloring each region either red, green, or blue in such a way that no neighboring
regions have the same color.
• The constraints require neighboring regions to have distinct colors. Since there are nine places where regions
border, there are nine constraints:
C = {SA ≠ WA, SA ≠ NT , SA ≠ Q, SA ≠ NSW , SA ≠ V, WA ≠ NT , NT ≠ Q, Q ≠ NSW , NSW ≠ V }
Solution (cont.)
• Here we are using abbreviations; SA ≠ WA is a shortcut for ((SA, WA), SA ≠ WA), where SA ≠ WA can be
fully enumerated in turn as {(red , green), (red , blue), (green , red ), (green , blue), (blue, red ), (blue,
green)}
• There are many possible solutions to this problem, such as {WA = red , NT = green ,Q = red , NSW =
green ,V = red , SA = blue, T = red }
CSP EXAMPLE 2