Constraint Satisfaction Problems (CSP)
Constraint Satisfaction Problems (CSP)
Problems (CSP)
What is Search For?
• Assumptions about the world : a single agent, deterministic actions,
fully observed state, discrete state space
• Planning: sequences of actions
• Want: path to the goal.
• Paths have various costs, depths.
• Heuristics give problem-specific guidance
• Identification: assignments to variables
• The goal itself is important, not path.
• All paths at same depth (for some formulations)
• CSPs are specialized identification problems
Standard Search and CSP
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 variables Xi with values from domain Di
◦ goal test is a set of constraints specifying allowable combinations of values for
subsets of variables
Allows useful general-purpose algorithms with more power than
standard search algorithms
Constraint Satisfaction Problems
• CSP is defined by a set of variables, X1,X2,……Xn, and a set of
constraints, C1,C2,….Cn.
• Each variable Xi has a non empty domain Di of possible values
• Each constraint Ci involves some subset of the variables and specifies
the allowable combinations of values for that subset.
More on CSP
• A state of the problem is defined by an assignment of values to some
or all 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 mentioned,
and a soln to a CSP is a complete assignment that satisfies all the
constraints
• Some CSP require a soln that maximizes an objective function
Example: Map Coloring
• Variables: WA, NA, Q, NSW, V, SA, T
• Domains: D = {red, green, blue}
• Constraints: adjacent regions must have
different colors
• Implicit:
• Explicit: (WA,NT) ∈ {(red,green),(red,blue),...,}
• Solutions are assignmets satisfying all
constrains, e.g:
{ WA = red, NT= green, Q = red, NSW=green,
V=red, SA=blue, T=green }
Example: N Queen
Formulation 1:
Variables:
Domains: {0,1}
Constraints:
Example: N Queen
𝑄1
Formulation 2:
𝑄2
Variables:
Domains: {1,2,3, … , N} 𝑄3
Constraints:
Implicit: non threatening 𝑄4
Explicit:
…
…
Constraint Graph
Binary CSP: each constraint relates two
variables
Constraint graph: nodes are variables, arcs are
constraints
General-purpose CSP algorithms use the
graph structure to speed up search.
E.g., Tasmania is an independent subproblem!
Varieties of CSPs and Constraints
• Discrete Variables
• Finite domains
• Size d means O(dn) complete assignments.
• E.g., Boolean CSPs, including Boolean satisfiability (NP-complete)
• Infinite domains (integers, strings, etc.)
• E.g., Scheduling: Variables = Job start times.
• Linear constraints solvable
• Nonlinear undecidable
• Continuous variables
• E.g., start/end times for Hubble Telescope observations
• Linear constraints solvable in polynomial time by LP methods
(see cs170 for a bit of this theory)
Varieties of Constraints
Unary constraints involve a single variable,
◦ e.g., SA ≠ green
Binary constraints involve pairs of variables,
◦ e.g., SA ≠ WA
Higher-order constraints involve 3 or more variables,
◦ e.g., cryptarithmetic column constraints
• WA=red and NT=green, one possible value for SA, so rather assign value
at Q we choose SA
• And later Q,NSW and V values are forced. Reduce the unnecessary
backtracking steps, failure will be detect easily
• minimum remaining values (MRV) heuristic
• Fail-first heuristic
Degree Heuristic
• Selecting the variable that involved in the largest number of
constraints on other unassigned variables
• Reduce the branching factor on future choices
• Tie-breaker among most constrained variables
• A binary CSP O(n2) arcs, each arc (xk,xj) inserted only d times so
O(n2d)..checking consistency of an arc can be done O(d2).
• Time complexity: O(n2d3)
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