SlideShare a Scribd company logo
Constraint Satisfaction
Problems
CHAPTER 6
Constraint Satisfaction Problems
We have so far explored the idea that 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, each state is atomic, or indivisible—a
black box with no internal structure.
However, there is 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. A
problem is solved when each variable has a value that satisfies all the constraints on the
variable.
A problem described this way is called a constraint satisfaction problem, or CSP
Constraint Satisfaction Problems_ AI2025
Constraint Satisfaction Problems
(contd…)
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.
Constraint Satisfaction Problems (contd…)
A constraint satisfaction problem consists of three components, X, D, and C:
• X is a set of variables, {X1, . . . ,Xn}.
• D is a set of domains, {D1, . . . ,Dn}, one for each variable.
• C is a set of constraints that specify allowable combinations of values.
Each domain Di consists of a set of allowable values, {v1, . . . , vk} for variable Xi.
Each constraint Ci 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.
Constraint Satisfaction Problems (contd…)
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:
1) Testing if a tuple is a member of the relation and
2) Enumerating the members of the relation.
For example, if X1 and X2 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)]> or as <(X1,X2), X1!= X2>.
Constraint Satisfaction Problems (Summary)
•Summary:
•Here the goal is to discover some problem state that satisfies a given set of
constraints.
•A constraint satisfaction problem (CSP) is defined by a set of variables X1, X2,
…..Xn and a set of constraints C1,C2,….Cm.
•Each variable Xi has a nonempty domain Di of possible values.
•Each constraint Ci involves some subset of the variables and specifies the
allowable combinations of values for that subset.
Constraint Satisfaction Problems(Summary)
(contd…)
• An assignment of values to some or all of the variables that does not violate
any constraints is called a consistent or legal assignment.
• A complete assignment is that in which every variable is mentioned and if it
satisfies all the constraints, then it is a solution.
Constraint Satisfaction Problems(Summary) (contd…)
• 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
• CSP allows useful general-purpose algorithms with more power than standard search
algorithms which are mostly problem specific.
Outline: Focus on next points of
discussion
• Constraint Satisfaction Problems (CSP)
• Backtracking search for CSPs
• Local search for CSPs
Constraint Satisfaction Problems
• Suppose that we are looking at a map of Australia showing each of its states and territories. 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. To formulate this as a CSP, we 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 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}
Constraint Satisfaction Problems
(contd…)
•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}
Example: Map-Coloring
• Variables : WA, NT, Q, NSW, V, SA, T
• Domains Di = {red, green, blue}
• Constraints: adjacent regions must have different colors
• e.g., WA ≠ NT, or <(WA,NT), WA != NT> where WA != NT can be one of the following
combinations:
{(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}
Example: Map-Coloring (contd…)
• Solutions are complete and consistent assignments, e.g., WA =
red, NT = green, Q = red, NSW = green, V = red, SA = blue, T =
green
CSP vs General State Space Search
•
Constraint graph
• Binary CSP: each constraint relates two variables
• Constraint graph: nodes are variables, arcs are constraints
Example problem: Job-shop scheduling
• Factories have the problem of scheduling a day’s worth of jobs, subject to various
constraints. In practice, many of these problems are solved with CSP techniques.
• Consider the problem of scheduling the assembly of a car. The whole job is
composed of tasks, and we can model each task as a variable, where the value of
each variable is the time that the task starts, expressed as an integer number of
minutes.
• Constraints can assert that one task must occur before so many tasks can go on at
once.
• Constraints can also specify that a task takes a certain amount of time to complete.
• We now consider a small part of the car assembly, consisting of 15 tasks: install
axles (front and back), affix all four wheels (right and left, front and back), tighten
nuts for each wheel, affix hubcaps, and inspect the final assembly.
Example problem: Job-shop scheduling (contd…)
• We can represent the tasks with 15 variables:
X = {AxleF, AxleB, WheelRF, WheelLF, WheelRB, WheelLB, NutsRF, NutsLF , NutsRB,
NutsLB, CapRF , CapLF , CapRB, CapLB, Inspect} .
• The value of each variable is the time that the task starts.
Precedence constraints between individual tasks:
• Whenever a task T1 must occur before task T2, and task T1 takes duration d1 to complete, we add an
arithmetic constraint of the form:
T1 + d1 ≤ T2
Example problem: Job-shop scheduling (contd…)
• In our example, the axles have to be in place before the wheels are put on, and it takes 10 minutes to install an
axle, so we write
AxleF + 10 ≤ WheelRF ; AxleF + 10 ≤ WheelLF ;
AxleB + 10 ≤ WheelRB; AxleB + 10 ≤ WheelLB .
• Next we say that, for each wheel, we must affix the wheel (which takes 1 minute), then tighten the nuts (2
minutes), and finally attach the hubcap (1 minute, but not represented yet):
WheelRF + 1 ≤ NutsRF ; NutsRF + 2 ≤ CapRF ;
WheelLF + 1 ≤ NutsLF ; NutsLF +2 ≤ CapLF ;
WheelRB + 1 ≤ NutsRB; NutsRB + 2 ≤ CapRB;
WheelLB + 1 ≤ NutsLB; NutsLB + 2 ≤ CapLB .
Example problem: Job-shop scheduling (contd…)
Disjunctive constraint:
•Suppose we have four workers to install wheels, but they have to share one tool
that helps put the axle in place. We need a disjunctive constraint to say that
AxleF and AxleB must not overlap in time; either one comes first or the other
does:
(AxleF + 10 ≤ AxleB) or (AxleB + 10 ≤ AxleF)
•This looks like a more complicated constraint, combining arithmetic and logic.
But it still reduces to a set of pairs of values that AxleF and AxleB can take on.
Example problem: Job-shop scheduling (contd…)
•
Variations on the CSP formalism
A) Discrete variables:
Discrete finite domains:
Examples: 1) Map-coloring problems
2) Job scheduling with time limits
3) 8-queens problem [This can also be viewed as a finite-
domain CSP, where the variables Q1, . . . ,Q8 are the positions of each
queen in columns 1, . . . , 8 and each variable has the domain Di = {1, 2, 3,
4, 5, 6, 7, 8}.]
[n variables, domain size d O(d
🡪 n
) = no. of possible complete assignments
e.g. Finite domain CSPs include Boolean CSPs, whose variables can be
either true or false. ]
Discrete variables…
• Boolean CSPs include as special cases some NP-complete problems.
• In the worst case , therefore, we can not expect to solve finite-domain CSPs in less than
exponential time.
• In most practical applications, however, general-purpose CSP algorithms can solve problems
orders of magnitude larger than those solvable via the general-purpose search algorithms.
Variations on the CSP formalism (contd…)
Discrete infinite domains:
Examples: 1) The set of integers or strings
2) The job-scheduling problem without deadline [There
would be an infinite number of start times for each variable.]
(With infinite domains, it is no longer possible to describe constraints
by enumerating all allowed combinations of values. Instead, a
constraint language must be used that understands constraints such
as T1 + d1 ≤ T2 directly, without enumerating the set of pairs of
allowable values for (T1, T2).)
Variations on the CSP formalism (contd…)
B) Continuous variables:
Continuous domains:
Constraint satisfaction problems with continuous domains are common in the real
world and are widely studied in the field of operations research.
Example: 1) Scheduling of experiments on the Hubble Space Telescope [It requires
very precise timing of observations; the start and finish of each observation and
maneuver are continuous-valued variables that must obey a variety of astronomical,
precedence, and power constraints.]
2) 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.]
Variations on the CSP formalism (contd…)
C) Constraints:
Unary constraint:
• It restricts the value of a single variable.
• Example: In the map-coloring problem it could be the case that South Australians won’t
tolerate the color green; we can express that with the unary constraint <(SA),SA != green>
Binary constraint:
• It relates two variables.
• Example: SA != NSW is a binary constraint. (A binary CSP is one with only binary
constraints; it can be represented as a constraint graph).
[There are also higher-order constraints such as Ternary constraint.
Example: Asserting that the value of Y is between X and Z, with the ternary constraint
Between(X, Y, Z).]
Variations on the CSP formalism (contd…)
Global Constraints:
• A constraint involving an arbitrary number of variables is called a global
constraint. (The name is traditional but confusing because it need not involve all
the variables in a problem).
• One of the most common global constraints is Alldiff , which says that all of the
variables involved in the constraint must have different values.
Examples:
• Sudoku problems (all variables in each row or column or 3 3 matrix must
˟
satisfy an Alldiff constraint.)
• Cryptarithmetic puzzles. (Each letter in a cryptarithmetic puzzle represents a
different digit.)
Sudoku problems
Sudoku problems (contd…)
Sudoku problems (contd…)
Cryptarithmetic Problems
Cryptarithmetic Problems (contd…)
• Variables: F T U W R O
• Domains: {0,1,2,3,4,5,6,7,8,9}
• Constraints: Alldiff (F,T,U,W,R,O)
O + O = R + 10 · C1
C1 + W + W = U + 10 · C2
C2 + T + T = O + 10 · C3
C3 = F, T ≠ 0, F ≠ 0
Cryptarithmetic Problems (contd…)
• These constraints can be
represented in a constraint
hypergraph as shown in the
figure.
• A hypergraph consists of
ordinary nodes (the circles
in the figure) and
hypernodes (the squares),
which represent n-ary
constraints.
Cryptarithmatic Problems (contd…)
Example: cryptarithmetic problem
C4 C3 C2 C1
S E N D
+ M O R E
________________
M O N E Y
1. D + E = 10 * C1 + Y
2. C1 + N + R = 10 * C2 + E
3. C2 + E + O = 10 * C3 + N
4. C3 + S + M = 10 * C4+ O
5. C4 = M = 1 (As M has to be non-zero.)
Where C1, C2, C3 and C4 can be either 0 or 1.
Other alphabets can take unique values from the set { 0,1, 2, 3, 4, 5, 6, 7, 9}
Example: cryptarithmetic problem (contd…)
C4 C3 C2 C1
S E N D
+ M O R E
-----------------------
M O N E Y
E = 2
E=5
D=7
C1=1 C1=0
SOLUTION: {S=9, E=5, N=6, D=7, M=1, O=0, R=8, Y=2} and { C1 =1, C2 = 1, C3 =0, C4 = 1 }
Initial
state
M=1 (As C4 =1)
S=8 OR 9
O=0 OR 1 O = 0
N=E OR E+1 N = E + 1
C2=1
N+R>8
E<>9 , E = 2, 3, 4 ends with conflict
N=6
C3= 0 AND S=9
R=9 - C1
5+D=Y OR 5+D=10 + Y
D = Y + 5
R = 8
Y= 2
R = 9
Contradictio
n as S=9
One of the solutions f0r this example
C4 C3 C2 C1
--------------------
S E N D
+ M O R E
______________
M O N E Y
1 0 1 1
--------------------
9 5 6 7
+ 1 0 8 5
______________
1 0 6 5 2
SOME MORE CRYPTARITHMETIC PROBLEMS
• MATH + MYTH = HARD
• ODD + ODD = EVEN
• CROSS + ROADS = DANGER
• TWO + TWO = FOUR
• BASE + BALL = GAMES
• TOUGH + DOUGH = RHYME
• YOUR + YOU = HEART
• FOUR + ONE = FIVE
• KANSAS + OHIO = OREGON
Real-world CSPs
• Assignment problems
• e.g., who teaches what class
• Timetabling problems
• e.g., which class is offered when and where?
• Transportation scheduling
• Factory scheduling
(Notice that many real-world problems involve real-valued variables)
Real-world CSPs (contd…)
• The constraints we have described so far have all been absolute constraints, violation of
which rules out a potential solution.
• Many real-world CSPs include preference constraints indicating which solutions are
preferred.
• For example, in a university class-scheduling problem, there are absolute constraints that no
professor can teach two classes at the same time. But we also may allow preference
constraints: Prof. R might prefer teaching in the morning, whereas Prof. N prefers teaching
in the afternoon. A schedule that has Prof. R teaching at 2 p.m. would still be an allowable
solution but would not be an optimal one.
• Preference constraints can often be encoded as costs on individual variable assignments—
for example, assigning an afternoon slot for Prof. R costs 2 points against the overall
objective function, whereas a morning slot costs 1.
• With this formulation, CSPs with preferences can be solved with optimization search
methods, either path-based or local. We call such a problem a constraint optimization
problem, or COP.
Real-world CSPs (contd…)
• 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 (use 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.)
• Constraint propagation may be intertwined with search, or it may be
done as a preprocessing step, before search starts. Sometimes this
preprocessing can solve the whole problem, so no search is required
at all.
Local Consistency
• The key idea is local consistency.
• If we treat each variable as a node in a graph and each binary constraint as an arc, then
the process of enforcing local consistency in each part of the graph causes inconsistent
values to be eliminated throughout the graph.
• There are different types of local consistency:
1) Node Inconsistency: A single variable (corresponding to a node in the CSP network)
is node-consistent if all the values in the variable’s domain satisfy the variable’s unary
constraints. For example, in the variant of the Australia map-coloring problem where South
Australians dislike green, the variable SA starts with domain {red, green, blue}, and we
can make it node consistent by eliminating green, leaving SA with the reduced domain {red
, blue}.
• We say that a network is node-consistent if every variable in the network is node-
consistent.
• 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.
(Ex.6.6)
Local Consistency (Exercise: 6.6)
Local Consistency (contd…)
•
Standard search formulation (incremental)
Let's start with the straightforward approach, then fix it.
States are defined by the values assigned so far:
• Initial state: the empty assignment { }
• Successor function: assign a value to an unassigned variable that does not conflict with current assignment
🡪 fail if no legal assignments
• Goal test: the current assignment is complete
1. This is the same for all CSPs
2. Every solution appears at depth n with n variables
use depth-first search
🡪
Backtracking search
• Variable assignments are commutative, i.e.,
[ WA = red then NT = green ] same as [ NT = green then WA = red ]
• Only need to consider assignments to a single variable at each node
• Depth-first search for CSPs with single-variable assignments is called backtracking search
• Backtracking search is the basic uninformed algorithm for CSPs
• Can solve n-queens for n ≈ 24
Backtracking search…
• A variant of depth-first search called backtracking search uses still less memory.
• In backtracking, only one successor is generated at a time rather than all successors; each
partially expanded node remembers which successor to generate next. In this way, only
O(m) memory is needed rather than O(bm).
• Backtracking search facilitates yet another memory-saving (and time-saving) trick: the idea
of generating a successor by modifying the current state description directly rather than
copying it first.
• This reduces the memory requirements to just one state description and O(m) actions.
• For this to work, we must be able to undo each modification when we go back to generate
the next successor.
• For problems with large state descriptions, such as robotic assembly, these techniques are
critical to success.
Backtracking search
Backtracking search
Backtracking example
Backtracking example
Backtracking example
Backtracking example
Improving backtracking efficiency
• General-purpose methods can give huge gains in speed:
• Which variable should be assigned next?
• In what order should its values be tried?
• Can we detect inevitable failure early?
Most constrained variable
• Most constrained variable:
choose the variable with the fewest legal values
• minimum remaining values (MRV) heuristic
Most constraining variable
• Tie-breaker among most constrained variables
• Most constraining variable:
• choose the variable with the most constraints on remaining variables
Least constraining value
• Given a variable, choose the least constraining value:
• the one that rules out the fewest values in the remaining variables
• Combining these heuristics makes 1000 queens feasible
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
Forward checking
Constraint propagation
• Forward checking propagates information from assigned to unassigned
variables, but doesn't provide early detection for all failures:
• NT and SA cannot both be blue!
• Constraint propagation repeatedly enforces constraints locally
Arc consistency
• Simplest form of propagation makes each arc consistent
• X 🡪Y is consistent iff
for every value x of X there is some allowed value y of Y
Arc consistency
• Simplest form of propagation makes each arc consistent
• X 🡪Y is consistent iff
for every value x of X there is some allowed value y of Y
Arc consistency
• Simplest form of propagation makes each arc consistent
• X 🡪Y is consistent iff
for every value x of X there is some allowed value y of Y
• If X loses a value, neighbors of X need to be rechecked
Arc consistency
• Simplest form of propagation makes each arc consistent
• X 🡪Y is consistent iff
for every value x of X there is some allowed value y of Y
• If X loses a value, neighbors of X need to be rechecked
• Arc consistency detects failure earlier than forward checking
• Can be run as a preprocessor or after each assignment
Arc consistency algorithm AC-3
• Time complexity: O(n2
d3
)
Local Search for CSPs: 4-Queen Problem
States:
4 queens in 4 columns (44
= 256 states)
Actions:
move queen in column
Goal test:
no attacks
Evaluation:
h(n) = number of attacks
[Given random initial state, can solve n-
queens in almost constant time for
arbitrary n with high probability (e.g., n =
10,000,000)]
Local Search for CSPs: 8-Queen Problem
Minimum Conflicts Algorithm (Local Search)
Local Search for CSPs: 8-Queen Problem
In choosing a new value
for a variable, the most
obvious heuristic is to
select the value that
results in the minimum
number of conflicts with
other variables—the
min-conflicts heuristic
Summary
• CSPs are a special kind of problem:
• states defined by values of a fixed set of variables
• goal test defined by constraints on variable values
• Backtracking = depth-first search with one variable assigned per node
• Variable ordering and value selection heuristics help significantly
• Forward checking prevents assignments that guarantee later failure
• Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies
• Iterative min-conflicts is usually effective in practice

More Related Content

PPT
presentation related to artificial intelligence.ppt
PPT
presentation on artificial intelligence autosaved
PPTX
AI UNIT 3 PPTs AI UNIT 3 PPT AI UNIT 3 PPT AI UNIT 3 PPT.pptx
PPT
ConstraintSatisfaction.ppt
PPTX
constraint satisfaction problems.pptx
PPTX
Artificial Intellligence Constraint Satisfaction Problem.pptx
PDF
AI 7 | Constraint Satisfaction Problem
PPTX
AI3391 Artificial Intelligence Session 21 CSP.pptx
presentation related to artificial intelligence.ppt
presentation on artificial intelligence autosaved
AI UNIT 3 PPTs AI UNIT 3 PPT AI UNIT 3 PPT AI UNIT 3 PPT.pptx
ConstraintSatisfaction.ppt
constraint satisfaction problems.pptx
Artificial Intellligence Constraint Satisfaction Problem.pptx
AI 7 | Constraint Satisfaction Problem
AI3391 Artificial Intelligence Session 21 CSP.pptx

Similar to Constraint Satisfaction Problems_ AI2025 (20)

PDF
Artificial Intelligence JNTUH Syllabusss
PPTX
Constraint satisfaction problems (csp)
PPTX
22PCOAM11 Unit 2: Session 10 CSP map coloring.pptx
PPTX
CH6,7.pptx
PPT
constrain satisfaction problem in artificial intelligence
PPT
constraintSat.ppt
PPT
Constraint Satisfaction problem in AI.ppt
PPT
A PPT on Constraint Satisfaction problems
PPT
modeling.ppt
PPT
Constraint Satisfaction in Artifical intelligennce.ppt
PPT
Constraint Satisfaction problem00456.ppt
PPTX
CS415 - Lecture 11 - CSPs I.pptx
PPT
csps.ppt
PDF
Solvers and Applications with CP
PPT
Satisfaction And Its Application To Ai Planning
PPTX
Constraint Specific Problem Problem.pptx
PPTX
Constraint satisfaction Problem Artificial Intelligence
PPTX
AI_Session 17 CSP.pptx
PPTX
lecture9 constraint problem and path finding
PDF
Ch5_Constraint Satisfaction Problems_Lecture 1.pdf
Artificial Intelligence JNTUH Syllabusss
Constraint satisfaction problems (csp)
22PCOAM11 Unit 2: Session 10 CSP map coloring.pptx
CH6,7.pptx
constrain satisfaction problem in artificial intelligence
constraintSat.ppt
Constraint Satisfaction problem in AI.ppt
A PPT on Constraint Satisfaction problems
modeling.ppt
Constraint Satisfaction in Artifical intelligennce.ppt
Constraint Satisfaction problem00456.ppt
CS415 - Lecture 11 - CSPs I.pptx
csps.ppt
Solvers and Applications with CP
Satisfaction And Its Application To Ai Planning
Constraint Specific Problem Problem.pptx
Constraint satisfaction Problem Artificial Intelligence
AI_Session 17 CSP.pptx
lecture9 constraint problem and path finding
Ch5_Constraint Satisfaction Problems_Lecture 1.pdf
Ad

Recently uploaded (20)

PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Project quality management in manufacturing
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Well-logging-methods_new................
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
737-MAX_SRG.pdf student reference guides
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
DOCX
573137875-Attendance-Management-System-original
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Current and future trends in Computer Vision.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Project quality management in manufacturing
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Well-logging-methods_new................
Foundation to blockchain - A guide to Blockchain Tech
Safety Seminar civil to be ensured for safe working.
Fundamentals of safety and accident prevention -final (1).pptx
737-MAX_SRG.pdf student reference guides
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
573137875-Attendance-Management-System-original
CYBER-CRIMES AND SECURITY A guide to understanding
R24 SURVEYING LAB MANUAL for civil enggi
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Operating System & Kernel Study Guide-1 - converted.pdf
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Current and future trends in Computer Vision.pptx
Ad

Constraint Satisfaction Problems_ AI2025

  • 2. Constraint Satisfaction Problems We have so far explored the idea that 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, each state is atomic, or indivisible—a black box with no internal structure. However, there is 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. A problem is solved when each variable has a value that satisfies all the constraints on the variable. A problem described this way is called a constraint satisfaction problem, or CSP
  • 4. Constraint Satisfaction Problems (contd…) 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.
  • 5. Constraint Satisfaction Problems (contd…) A constraint satisfaction problem consists of three components, X, D, and C: • X is a set of variables, {X1, . . . ,Xn}. • D is a set of domains, {D1, . . . ,Dn}, one for each variable. • C is a set of constraints that specify allowable combinations of values. Each domain Di consists of a set of allowable values, {v1, . . . , vk} for variable Xi. Each constraint Ci 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.
  • 6. Constraint Satisfaction Problems (contd…) 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: 1) Testing if a tuple is a member of the relation and 2) Enumerating the members of the relation. For example, if X1 and X2 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)]> or as <(X1,X2), X1!= X2>.
  • 7. Constraint Satisfaction Problems (Summary) •Summary: •Here the goal is to discover some problem state that satisfies a given set of constraints. •A constraint satisfaction problem (CSP) is defined by a set of variables X1, X2, …..Xn and a set of constraints C1,C2,….Cm. •Each variable Xi has a nonempty domain Di of possible values. •Each constraint Ci involves some subset of the variables and specifies the allowable combinations of values for that subset.
  • 8. Constraint Satisfaction Problems(Summary) (contd…) • An assignment of values to some or all of the variables that does not violate any constraints is called a consistent or legal assignment. • A complete assignment is that in which every variable is mentioned and if it satisfies all the constraints, then it is a solution.
  • 9. Constraint Satisfaction Problems(Summary) (contd…) • 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 • CSP allows useful general-purpose algorithms with more power than standard search algorithms which are mostly problem specific.
  • 10. Outline: Focus on next points of discussion • Constraint Satisfaction Problems (CSP) • Backtracking search for CSPs • Local search for CSPs
  • 11. Constraint Satisfaction Problems • Suppose that we are looking at a map of Australia showing each of its states and territories. 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. To formulate this as a CSP, we 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 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}
  • 12. Constraint Satisfaction Problems (contd…) •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}
  • 13. Example: Map-Coloring • Variables : WA, NT, Q, NSW, V, SA, T • Domains Di = {red, green, blue} • Constraints: adjacent regions must have different colors • e.g., WA ≠ NT, or <(WA,NT), WA != NT> where WA != NT can be one of the following combinations: {(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}
  • 14. Example: Map-Coloring (contd…) • Solutions are complete and consistent assignments, e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green
  • 15. CSP vs General State Space Search •
  • 16. Constraint graph • Binary CSP: each constraint relates two variables • Constraint graph: nodes are variables, arcs are constraints
  • 17. Example problem: Job-shop scheduling • Factories have the problem of scheduling a day’s worth of jobs, subject to various constraints. In practice, many of these problems are solved with CSP techniques. • Consider the problem of scheduling the assembly of a car. The whole job is composed of tasks, and we can model each task as a variable, where the value of each variable is the time that the task starts, expressed as an integer number of minutes. • Constraints can assert that one task must occur before so many tasks can go on at once. • Constraints can also specify that a task takes a certain amount of time to complete. • We now consider a small part of the car assembly, consisting of 15 tasks: install axles (front and back), affix all four wheels (right and left, front and back), tighten nuts for each wheel, affix hubcaps, and inspect the final assembly.
  • 18. Example problem: Job-shop scheduling (contd…) • We can represent the tasks with 15 variables: X = {AxleF, AxleB, WheelRF, WheelLF, WheelRB, WheelLB, NutsRF, NutsLF , NutsRB, NutsLB, CapRF , CapLF , CapRB, CapLB, Inspect} . • The value of each variable is the time that the task starts. Precedence constraints between individual tasks: • Whenever a task T1 must occur before task T2, and task T1 takes duration d1 to complete, we add an arithmetic constraint of the form: T1 + d1 ≤ T2
  • 19. Example problem: Job-shop scheduling (contd…) • In our example, the axles have to be in place before the wheels are put on, and it takes 10 minutes to install an axle, so we write AxleF + 10 ≤ WheelRF ; AxleF + 10 ≤ WheelLF ; AxleB + 10 ≤ WheelRB; AxleB + 10 ≤ WheelLB . • Next we say that, for each wheel, we must affix the wheel (which takes 1 minute), then tighten the nuts (2 minutes), and finally attach the hubcap (1 minute, but not represented yet): WheelRF + 1 ≤ NutsRF ; NutsRF + 2 ≤ CapRF ; WheelLF + 1 ≤ NutsLF ; NutsLF +2 ≤ CapLF ; WheelRB + 1 ≤ NutsRB; NutsRB + 2 ≤ CapRB; WheelLB + 1 ≤ NutsLB; NutsLB + 2 ≤ CapLB .
  • 20. Example problem: Job-shop scheduling (contd…) Disjunctive constraint: •Suppose we have four workers to install wheels, but they have to share one tool that helps put the axle in place. We need a disjunctive constraint to say that AxleF and AxleB must not overlap in time; either one comes first or the other does: (AxleF + 10 ≤ AxleB) or (AxleB + 10 ≤ AxleF) •This looks like a more complicated constraint, combining arithmetic and logic. But it still reduces to a set of pairs of values that AxleF and AxleB can take on.
  • 21. Example problem: Job-shop scheduling (contd…) •
  • 22. Variations on the CSP formalism A) Discrete variables: Discrete finite domains: Examples: 1) Map-coloring problems 2) Job scheduling with time limits 3) 8-queens problem [This can also be viewed as a finite- domain CSP, where the variables Q1, . . . ,Q8 are the positions of each queen in columns 1, . . . , 8 and each variable has the domain Di = {1, 2, 3, 4, 5, 6, 7, 8}.] [n variables, domain size d O(d 🡪 n ) = no. of possible complete assignments e.g. Finite domain CSPs include Boolean CSPs, whose variables can be either true or false. ]
  • 23. Discrete variables… • Boolean CSPs include as special cases some NP-complete problems. • In the worst case , therefore, we can not expect to solve finite-domain CSPs in less than exponential time. • In most practical applications, however, general-purpose CSP algorithms can solve problems orders of magnitude larger than those solvable via the general-purpose search algorithms.
  • 24. Variations on the CSP formalism (contd…) Discrete infinite domains: Examples: 1) The set of integers or strings 2) The job-scheduling problem without deadline [There would be an infinite number of start times for each variable.] (With infinite domains, it is no longer possible to describe constraints by enumerating all allowed combinations of values. Instead, a constraint language must be used that understands constraints such as T1 + d1 ≤ T2 directly, without enumerating the set of pairs of allowable values for (T1, T2).)
  • 25. Variations on the CSP formalism (contd…) B) Continuous variables: Continuous domains: Constraint satisfaction problems with continuous domains are common in the real world and are widely studied in the field of operations research. Example: 1) Scheduling of experiments on the Hubble Space Telescope [It requires very precise timing of observations; the start and finish of each observation and maneuver are continuous-valued variables that must obey a variety of astronomical, precedence, and power constraints.] 2) 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.]
  • 26. Variations on the CSP formalism (contd…) C) Constraints: Unary constraint: • It restricts the value of a single variable. • Example: In the map-coloring problem it could be the case that South Australians won’t tolerate the color green; we can express that with the unary constraint <(SA),SA != green> Binary constraint: • It relates two variables. • Example: SA != NSW is a binary constraint. (A binary CSP is one with only binary constraints; it can be represented as a constraint graph). [There are also higher-order constraints such as Ternary constraint. Example: Asserting that the value of Y is between X and Z, with the ternary constraint Between(X, Y, Z).]
  • 27. Variations on the CSP formalism (contd…) Global Constraints: • A constraint involving an arbitrary number of variables is called a global constraint. (The name is traditional but confusing because it need not involve all the variables in a problem). • One of the most common global constraints is Alldiff , which says that all of the variables involved in the constraint must have different values. Examples: • Sudoku problems (all variables in each row or column or 3 3 matrix must ˟ satisfy an Alldiff constraint.) • Cryptarithmetic puzzles. (Each letter in a cryptarithmetic puzzle represents a different digit.)
  • 32. Cryptarithmetic Problems (contd…) • Variables: F T U W R O • Domains: {0,1,2,3,4,5,6,7,8,9} • Constraints: Alldiff (F,T,U,W,R,O) O + O = R + 10 · C1 C1 + W + W = U + 10 · C2 C2 + T + T = O + 10 · C3 C3 = F, T ≠ 0, F ≠ 0
  • 33. Cryptarithmetic Problems (contd…) • These constraints can be represented in a constraint hypergraph as shown in the figure. • A hypergraph consists of ordinary nodes (the circles in the figure) and hypernodes (the squares), which represent n-ary constraints.
  • 35. Example: cryptarithmetic problem C4 C3 C2 C1 S E N D + M O R E ________________ M O N E Y 1. D + E = 10 * C1 + Y 2. C1 + N + R = 10 * C2 + E 3. C2 + E + O = 10 * C3 + N 4. C3 + S + M = 10 * C4+ O 5. C4 = M = 1 (As M has to be non-zero.) Where C1, C2, C3 and C4 can be either 0 or 1. Other alphabets can take unique values from the set { 0,1, 2, 3, 4, 5, 6, 7, 9}
  • 36. Example: cryptarithmetic problem (contd…) C4 C3 C2 C1 S E N D + M O R E ----------------------- M O N E Y E = 2 E=5 D=7 C1=1 C1=0 SOLUTION: {S=9, E=5, N=6, D=7, M=1, O=0, R=8, Y=2} and { C1 =1, C2 = 1, C3 =0, C4 = 1 } Initial state M=1 (As C4 =1) S=8 OR 9 O=0 OR 1 O = 0 N=E OR E+1 N = E + 1 C2=1 N+R>8 E<>9 , E = 2, 3, 4 ends with conflict N=6 C3= 0 AND S=9 R=9 - C1 5+D=Y OR 5+D=10 + Y D = Y + 5 R = 8 Y= 2 R = 9 Contradictio n as S=9
  • 37. One of the solutions f0r this example C4 C3 C2 C1 -------------------- S E N D + M O R E ______________ M O N E Y 1 0 1 1 -------------------- 9 5 6 7 + 1 0 8 5 ______________ 1 0 6 5 2
  • 38. SOME MORE CRYPTARITHMETIC PROBLEMS • MATH + MYTH = HARD • ODD + ODD = EVEN • CROSS + ROADS = DANGER • TWO + TWO = FOUR • BASE + BALL = GAMES • TOUGH + DOUGH = RHYME • YOUR + YOU = HEART • FOUR + ONE = FIVE • KANSAS + OHIO = OREGON
  • 39. Real-world CSPs • Assignment problems • e.g., who teaches what class • Timetabling problems • e.g., which class is offered when and where? • Transportation scheduling • Factory scheduling (Notice that many real-world problems involve real-valued variables)
  • 40. Real-world CSPs (contd…) • The constraints we have described so far have all been absolute constraints, violation of which rules out a potential solution. • Many real-world CSPs include preference constraints indicating which solutions are preferred. • For example, in a university class-scheduling problem, there are absolute constraints that no professor can teach two classes at the same time. But we also may allow preference constraints: Prof. R might prefer teaching in the morning, whereas Prof. N prefers teaching in the afternoon. A schedule that has Prof. R teaching at 2 p.m. would still be an allowable solution but would not be an optimal one. • Preference constraints can often be encoded as costs on individual variable assignments— for example, assigning an afternoon slot for Prof. R costs 2 points against the overall objective function, whereas a morning slot costs 1. • With this formulation, CSPs with preferences can be solved with optimization search methods, either path-based or local. We call such a problem a constraint optimization problem, or COP.
  • 41. Real-world CSPs (contd…) • 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 (use 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.) • Constraint propagation may be intertwined with search, or it may be done as a preprocessing step, before search starts. Sometimes this preprocessing can solve the whole problem, so no search is required at all.
  • 42. Local Consistency • The key idea is local consistency. • If we treat each variable as a node in a graph and each binary constraint as an arc, then the process of enforcing local consistency in each part of the graph causes inconsistent values to be eliminated throughout the graph. • There are different types of local consistency: 1) Node Inconsistency: A single variable (corresponding to a node in the CSP network) is node-consistent if all the values in the variable’s domain satisfy the variable’s unary constraints. For example, in the variant of the Australia map-coloring problem where South Australians dislike green, the variable SA starts with domain {red, green, blue}, and we can make it node consistent by eliminating green, leaving SA with the reduced domain {red , blue}. • We say that a network is node-consistent if every variable in the network is node- consistent. • 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. (Ex.6.6)
  • 45. Standard search formulation (incremental) Let's start with the straightforward approach, then fix it. States are defined by the values assigned so far: • Initial state: the empty assignment { } • Successor function: assign a value to an unassigned variable that does not conflict with current assignment 🡪 fail if no legal assignments • Goal test: the current assignment is complete 1. This is the same for all CSPs 2. Every solution appears at depth n with n variables use depth-first search 🡪
  • 46. Backtracking search • Variable assignments are commutative, i.e., [ WA = red then NT = green ] same as [ NT = green then WA = red ] • Only need to consider assignments to a single variable at each node • Depth-first search for CSPs with single-variable assignments is called backtracking search • Backtracking search is the basic uninformed algorithm for CSPs • Can solve n-queens for n ≈ 24
  • 47. Backtracking search… • A variant of depth-first search called backtracking search uses still less memory. • In backtracking, only one successor is generated at a time rather than all successors; each partially expanded node remembers which successor to generate next. In this way, only O(m) memory is needed rather than O(bm). • Backtracking search facilitates yet another memory-saving (and time-saving) trick: the idea of generating a successor by modifying the current state description directly rather than copying it first. • This reduces the memory requirements to just one state description and O(m) actions. • For this to work, we must be able to undo each modification when we go back to generate the next successor. • For problems with large state descriptions, such as robotic assembly, these techniques are critical to success.
  • 54. Improving backtracking efficiency • General-purpose methods can give huge gains in speed: • Which variable should be assigned next? • In what order should its values be tried? • Can we detect inevitable failure early?
  • 55. Most constrained variable • Most constrained variable: choose the variable with the fewest legal values • minimum remaining values (MRV) heuristic
  • 56. Most constraining variable • Tie-breaker among most constrained variables • Most constraining variable: • choose the variable with the most constraints on remaining variables
  • 57. Least constraining value • Given a variable, choose the least constraining value: • the one that rules out the fewest values in the remaining variables • Combining these heuristics makes 1000 queens feasible
  • 58. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values
  • 59. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values
  • 60. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values
  • 61. Forward checking • Idea: • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values
  • 63. Constraint propagation • Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures: • NT and SA cannot both be blue! • Constraint propagation repeatedly enforces constraints locally
  • 64. Arc consistency • Simplest form of propagation makes each arc consistent • X 🡪Y is consistent iff for every value x of X there is some allowed value y of Y
  • 65. Arc consistency • Simplest form of propagation makes each arc consistent • X 🡪Y is consistent iff for every value x of X there is some allowed value y of Y
  • 66. Arc consistency • Simplest form of propagation makes each arc consistent • X 🡪Y is consistent iff for every value x of X there is some allowed value y of Y • If X loses a value, neighbors of X need to be rechecked
  • 67. Arc consistency • Simplest form of propagation makes each arc consistent • X 🡪Y is consistent iff for every value x of X there is some allowed value y of Y • If X loses a value, neighbors of X need to be rechecked • Arc consistency detects failure earlier than forward checking • Can be run as a preprocessor or after each assignment
  • 68. Arc consistency algorithm AC-3 • Time complexity: O(n2 d3 )
  • 69. Local Search for CSPs: 4-Queen Problem States: 4 queens in 4 columns (44 = 256 states) Actions: move queen in column Goal test: no attacks Evaluation: h(n) = number of attacks [Given random initial state, can solve n- queens in almost constant time for arbitrary n with high probability (e.g., n = 10,000,000)]
  • 70. Local Search for CSPs: 8-Queen Problem
  • 71. Minimum Conflicts Algorithm (Local Search)
  • 72. Local Search for CSPs: 8-Queen Problem In choosing a new value for a variable, the most obvious heuristic is to select the value that results in the minimum number of conflicts with other variables—the min-conflicts heuristic
  • 73. Summary • CSPs are a special kind of problem: • states defined by values of a fixed set of variables • goal test defined by constraints on variable values • Backtracking = depth-first search with one variable assigned per node • Variable ordering and value selection heuristics help significantly • Forward checking prevents assignments that guarantee later failure • Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies • Iterative min-conflicts is usually effective in practice

Editor's Notes

  • #6: 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)] or as (X1,X2),X1 = X2.