SlideShare a Scribd company logo
Artificial Intelligence
Constraint Satisfaction
Problems
Constraint Satisfaction
Problems (CSPs)
Definition:
• State is defined by a set of variables Xi (= factored state description)
• Each variable can have a value from domain Di or be unassigned (partial solution).
• Constraints are a set of rules specifying allowable combinations of values for subsets of variables (e.g., 𝑋
𝑋1 ≠
𝑋
𝑋7 or 𝑋
𝑋2 > 𝑋
𝑋9 + 3)
• Solution: a state that is a
a) Consistent assignment: satisfies all constraints
b) Complete assignment: assigns value to each variable
Differences: ”generic” tree search:
• Atomic states (variables are only used to create human readable labels or calculate heuristics)
• States are always complete assignments.
• Constrains are implicit in the transition function.
Differences: Local search
• Factored representation to find local moves.
• Always complete assignments.
• Constraints may not be met.
General-purpose algorithms for CSP with more power than standard search algorithms exit.
+ variables
can have no
value!
Example: Map Coloring (Graph coloring)
• Variables representing state: WA, NT, Q, NSW, V, SA, T
• Variable Domains: {red, green, blue}
• Constraints: adjacent regions must have different colors
e.g.,
WA ≠ NT ⇔ (WA, NT) in {(red, green), (red,
blue),
(green, red), (green, blue), (blue, red), (blue, green)}
Problem Constraint graph
Example: Map Coloring
Solutions are complete and consistent assignments, e.g.,
WA = red, NT = green, Q = red, NSW = green,
V = red, SA = blue, T = green
Example: N-Queens
• Variables: 𝑋𝑋𝑖
𝑖
𝑖 for 𝑖, 𝑖𝑖 ∈ {1, 2,
… , 𝑁}
• Domains: {0, 1} # Queen: no/yes
• Constraints:
i,j Xij = N
(Xij, Xik)  {(0, 0), (0, 1), (1, 0)} # cannot be in same col.
(Xij, Xkj)  {(0, 0), (0, 1), (1, 0)} # cannot be in same row.
(Xij, Xi+k, j+k)  {(0, 0), (0, 1), (1, 0)} # cannot be diagonal
(Xij, Xi+k, j–k)  {(0, 0), (0, 1), (1, 0)} # cannot be diagonal
Xij
i
j
for 𝑖, 𝑖𝑖, 𝑘 ∈ {1, 2,
… , 𝑁}
N-Queens: Alternative Formulation
• Variables: 𝑄𝑄1, 𝑄𝑄2, … , 𝑄
𝑄𝑁
• Domains: {1, 2, … , 𝑁} # row for each
col.
• Constraints:
 i, j non-threatening (Qi , Qj)
Q2 Q3
Q1 Q4
Example:
Q1 = 2, Q2 = 4, Q3 = 1, Q4 = 3
4
3
2
1
Example: Cryptarithmetic Puzzle
• Variables: T, W, O, F, U, R
X1, X2
• Domains: {0, 1, 2, …, 9}
• Constraints:
Alldiff(T, W, O, F, U, R)
O + O = R + 10 * X1
W + W + X1 = U + 10 * X2
T + T + X2 = O + 10 * F
T ≠ 0, F ≠ 0
Given Puzzle:
Find values for the letters.
Each letter stands for a
different digit.
Example: Sudoku
• Variables: Xij
• Domains: {1, 2, …, 9}
• Constraints:
Alldiff(Xij in the same unit)
Alldiff(X in the same row)
ij
Alldiff(Xij in the same column)
Xij
Some Popular Types of CSPs
• Boolean Satisfiability Problem (SAT)
Find variable assignments that makes a Boolean expression
(often expressed in conjunctive normal form) evaluate as true.
(x1 ∨ ¬x2) ∧ (¬x1 ∨ x2 ∨ x3) ∧ ¬x1 = True
• Integer Programming
Variables are restricted to integers. Find a feasible solution that
satisfies all constraints. The traveling salesman problem can be
expressed as an integer program.
• Linear Programming
Variables are continuous and constraints
are linear (in)equalities.
Find a feasible solution using, e.g.,
the simplex algorithm.
NP-complete
Real-world CSPs
•Assignment problems
e.g., who teaches what class for a fixed schedule. Teacher cannot
be in two classes at the same time!
•Timetable problems
e.g., which class is offered when and where? No two classes in
the same room at the same problem.
•Scheduling in transportation and production (e.g., order
of production steps).
•Many problems can naturally also be formulated as
CSPs.
•More examples of CSPs: http://www.csplib.org/
CSP as a Standard Search Formulation
State:
• Values assigned so far
Initial state:
• The empty assignment { } (all
variables are unassigned)
Successor function:
• Choose an unassigned variable and assign it a value
that does not violate any constraints
• Fail if no legal assignment is found
Goal state:
• Any complete and consistent assignment.
Backtracking Search
• In CSP’s, variable assignments are commutative
For example,
[WA = red then NT = green] is the same as
[NT = green then WA = red].  Order is not important
• We can build a search tree that assigns the value to
one variable per level.
• Tree depth n (number of variables)
• Number of leaves: dn (d is the number of values per
variable)
• Depth-first search for CSPs with single-variable assignments
is called backtracking search.
Example: Backtracking Search (DFS)
…
fail
Backtracking Search Algorithm
Improving backtracking efficiency:
• Which variable should be assigned next?
• In what order should its values be tried?
• Can we detect inevitable failure early?
Call: Recursive-Backtracking({}, csp)
Similar to move ordering in games.
Tree pruning (like in alpha-beta search)
Variable/Value Ordering
Which variable should be assigned next?
• Most constrained variable:
• Keep track of remaining legal values for unassigned variables (using
constraints).
• Choose the variable with the fewest legal values left.
• A.k.a. minimum remaining values (MRV) heuristic.
In which order should its values be tried?
• Choose the least constraining value:
• The value that rules out the fewest values in the remaining
variables.
Early Detection of Failure:
Forward Checking Node Consistency
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values (i.e.,
minimum remaining values = 0)
Stop and backtrack
• NT and SA cannot both be blue! This violates the constraint.
Early Detection of Failure:
Forward Checking Arc Consistency
• X is arc consistent wrt Y iff for every value of X there is some
allowed value of Y.
• Make X arc consistent wrt Y by throwing out any values of X for
which there is no allowed value of Y.
1. NWS cannot be blue
because SA has to be
blue.
2. V cannot be red because
NSW has to be red.
3. SA cannot be blue
because NT is blue.
4. Fail and backtrack
• Arc consistency detects failure earlier than node
consistency
• There are more consistency checks (path consistency, K-
Backtracking Search With Ordering and
Early Failure Detection
Call: Recursive-Backtracking({}, csp)
If (inference(csp, var, assignment) ==
failure) return failure
# Check consistency here (called “inference”) and backtrack if we know that the
branch will lead to failure.
Local search for CSPs
Local search can attempt to reduce unsatisfied constraints by the min-conflicts
heuristic:
1. Select a conflicted variable and
2. Choose a new value that produces violates the fewest constraints (local
improvement step)
3. Repeat till all constraints are met.
Local search is often very effective for CSPs.
CSP algorithms
• Allow incomplete states.
• States must satisfy all constraints.
Local Search works only with
• Only “complete” states (all variables assigned)
• Allows states with unsatisfied constraints.
vs.
Summary
• CSPs are a special type of search problem:
• States are structured and defined by a set of variables and values
assignments
• Variables can be unassigned
• Goal test defined by
• Consistency with constraints
• Completeness of assignment
• Backtracking search = depth-first search where a successor state is
generated by a consistent value assignment to a single
unassigned variable
• Starts with {} and only considers consistent assignments.
• Variable ordering and value selection heuristics can help significantly
• Forward checking prevents assignments that guarantee later failure
• Local search can be used to search the space of all complete
assignments for consistent assignments = min-conflicts heuristic.

More Related Content

PPT
Constraint Satisfaction problem in AI.ppt
PPT
constraintSat.ppt
PPTX
lecture9 constraint problem and path finding
PPT
Bounded Model Checking
PPT
05-constraint-satisfaction-problems-(us).ppt
PPT
Lect6 csp
PPTX
Constraint satisfaction problems (csp)
PDF
Artificial Intelligence JNTUH Syllabusss
Constraint Satisfaction problem in AI.ppt
constraintSat.ppt
lecture9 constraint problem and path finding
Bounded Model Checking
05-constraint-satisfaction-problems-(us).ppt
Lect6 csp
Constraint satisfaction problems (csp)
Artificial Intelligence JNTUH Syllabusss

Similar to Artificial Intellligence Constraint Satisfaction Problem.pptx (20)

PPT
Sudoku
PPT
CSP this is csp csp csp cspc p csp cp.ppt
PPT
ConstraintSatisfaction.ppt
PPTX
CS415 - Lecture 11 - CSPs I.pptx
PPT
Cs ps, sat, fol resolution strategies
PPTX
AI Unit-3(Ch-6_CSP) Constraint satisfaction problem.pptx
PPT
CSP UNIT 2 AIML.ppt
PPT
presentation related to artificial intelligence.ppt
PPT
presentation on artificial intelligence autosaved
PPT
Solving problems by searching
PDF
Paper study: Learning to solve circuit sat
PPT
Constraint_Satisfaction problem based_slides.ppt
PPTX
CH6,7.pptx
PDF
Extra Lecture - Support Vector Machines (SVM), a lecture in subject module St...
PPT
A PPT on Constraint Satisfaction problems
PDF
nlp2.pdf
PPTX
Undecidable Problems and Approximation Algorithms
PPT
csps.ppt
PPTX
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
PPT
02-solving-problems-by-searching-(us).ppt
Sudoku
CSP this is csp csp csp cspc p csp cp.ppt
ConstraintSatisfaction.ppt
CS415 - Lecture 11 - CSPs I.pptx
Cs ps, sat, fol resolution strategies
AI Unit-3(Ch-6_CSP) Constraint satisfaction problem.pptx
CSP UNIT 2 AIML.ppt
presentation related to artificial intelligence.ppt
presentation on artificial intelligence autosaved
Solving problems by searching
Paper study: Learning to solve circuit sat
Constraint_Satisfaction problem based_slides.ppt
CH6,7.pptx
Extra Lecture - Support Vector Machines (SVM), a lecture in subject module St...
A PPT on Constraint Satisfaction problems
nlp2.pdf
Undecidable Problems and Approximation Algorithms
csps.ppt
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
02-solving-problems-by-searching-(us).ppt
Ad

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Empowerment Technology for Senior High School Guide
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Introduction to Building Materials
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
History, Philosophy and sociology of education (1).pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
IGGE1 Understanding the Self1234567891011
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Empowerment Technology for Senior High School Guide
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Introduction to Building Materials
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
History, Philosophy and sociology of education (1).pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Weekly quiz Compilation Jan -July 25.pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
IGGE1 Understanding the Self1234567891011
Paper A Mock Exam 9_ Attempt review.pdf.
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Unit 4 Computer Architecture Multicore Processor.pptx
Ad

Artificial Intellligence Constraint Satisfaction Problem.pptx

  • 2. Constraint Satisfaction Problems (CSPs) Definition: • State is defined by a set of variables Xi (= factored state description) • Each variable can have a value from domain Di or be unassigned (partial solution). • Constraints are a set of rules specifying allowable combinations of values for subsets of variables (e.g., 𝑋 𝑋1 ≠ 𝑋 𝑋7 or 𝑋 𝑋2 > 𝑋 𝑋9 + 3) • Solution: a state that is a a) Consistent assignment: satisfies all constraints b) Complete assignment: assigns value to each variable Differences: ”generic” tree search: • Atomic states (variables are only used to create human readable labels or calculate heuristics) • States are always complete assignments. • Constrains are implicit in the transition function. Differences: Local search • Factored representation to find local moves. • Always complete assignments. • Constraints may not be met. General-purpose algorithms for CSP with more power than standard search algorithms exit. + variables can have no value!
  • 3. Example: Map Coloring (Graph coloring) • Variables representing state: WA, NT, Q, NSW, V, SA, T • Variable Domains: {red, green, blue} • Constraints: adjacent regions must have different colors e.g., WA ≠ NT ⇔ (WA, NT) in {(red, green), (red, blue), (green, red), (green, blue), (blue, red), (blue, green)} Problem Constraint graph
  • 4. Example: Map Coloring Solutions are complete and consistent assignments, e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green
  • 5. Example: N-Queens • Variables: 𝑋𝑋𝑖 𝑖 𝑖 for 𝑖, 𝑖𝑖 ∈ {1, 2, … , 𝑁} • Domains: {0, 1} # Queen: no/yes • Constraints: i,j Xij = N (Xij, Xik)  {(0, 0), (0, 1), (1, 0)} # cannot be in same col. (Xij, Xkj)  {(0, 0), (0, 1), (1, 0)} # cannot be in same row. (Xij, Xi+k, j+k)  {(0, 0), (0, 1), (1, 0)} # cannot be diagonal (Xij, Xi+k, j–k)  {(0, 0), (0, 1), (1, 0)} # cannot be diagonal Xij i j for 𝑖, 𝑖𝑖, 𝑘 ∈ {1, 2, … , 𝑁}
  • 6. N-Queens: Alternative Formulation • Variables: 𝑄𝑄1, 𝑄𝑄2, … , 𝑄 𝑄𝑁 • Domains: {1, 2, … , 𝑁} # row for each col. • Constraints:  i, j non-threatening (Qi , Qj) Q2 Q3 Q1 Q4 Example: Q1 = 2, Q2 = 4, Q3 = 1, Q4 = 3 4 3 2 1
  • 7. Example: Cryptarithmetic Puzzle • Variables: T, W, O, F, U, R X1, X2 • Domains: {0, 1, 2, …, 9} • Constraints: Alldiff(T, W, O, F, U, R) O + O = R + 10 * X1 W + W + X1 = U + 10 * X2 T + T + X2 = O + 10 * F T ≠ 0, F ≠ 0 Given Puzzle: Find values for the letters. Each letter stands for a different digit.
  • 8. Example: Sudoku • Variables: Xij • Domains: {1, 2, …, 9} • Constraints: Alldiff(Xij in the same unit) Alldiff(X in the same row) ij Alldiff(Xij in the same column) Xij
  • 9. Some Popular Types of CSPs • Boolean Satisfiability Problem (SAT) Find variable assignments that makes a Boolean expression (often expressed in conjunctive normal form) evaluate as true. (x1 ∨ ¬x2) ∧ (¬x1 ∨ x2 ∨ x3) ∧ ¬x1 = True • Integer Programming Variables are restricted to integers. Find a feasible solution that satisfies all constraints. The traveling salesman problem can be expressed as an integer program. • Linear Programming Variables are continuous and constraints are linear (in)equalities. Find a feasible solution using, e.g., the simplex algorithm. NP-complete
  • 10. Real-world CSPs •Assignment problems e.g., who teaches what class for a fixed schedule. Teacher cannot be in two classes at the same time! •Timetable problems e.g., which class is offered when and where? No two classes in the same room at the same problem. •Scheduling in transportation and production (e.g., order of production steps). •Many problems can naturally also be formulated as CSPs. •More examples of CSPs: http://www.csplib.org/
  • 11. CSP as a Standard Search Formulation State: • Values assigned so far Initial state: • The empty assignment { } (all variables are unassigned) Successor function: • Choose an unassigned variable and assign it a value that does not violate any constraints • Fail if no legal assignment is found Goal state: • Any complete and consistent assignment.
  • 12. Backtracking Search • In CSP’s, variable assignments are commutative For example, [WA = red then NT = green] is the same as [NT = green then WA = red].  Order is not important • We can build a search tree that assigns the value to one variable per level. • Tree depth n (number of variables) • Number of leaves: dn (d is the number of values per variable) • Depth-first search for CSPs with single-variable assignments is called backtracking search.
  • 14. Backtracking Search Algorithm Improving backtracking efficiency: • Which variable should be assigned next? • In what order should its values be tried? • Can we detect inevitable failure early? Call: Recursive-Backtracking({}, csp) Similar to move ordering in games. Tree pruning (like in alpha-beta search)
  • 15. Variable/Value Ordering Which variable should be assigned next? • Most constrained variable: • Keep track of remaining legal values for unassigned variables (using constraints). • Choose the variable with the fewest legal values left. • A.k.a. minimum remaining values (MRV) heuristic. In which order should its values be tried? • Choose the least constraining value: • The value that rules out the fewest values in the remaining variables.
  • 16. Early Detection of Failure: Forward Checking Node Consistency • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values (i.e., minimum remaining values = 0) Stop and backtrack • NT and SA cannot both be blue! This violates the constraint.
  • 17. Early Detection of Failure: Forward Checking Arc Consistency • X is arc consistent wrt Y iff for every value of X there is some allowed value of Y. • Make X arc consistent wrt Y by throwing out any values of X for which there is no allowed value of Y. 1. NWS cannot be blue because SA has to be blue. 2. V cannot be red because NSW has to be red. 3. SA cannot be blue because NT is blue. 4. Fail and backtrack • Arc consistency detects failure earlier than node consistency • There are more consistency checks (path consistency, K-
  • 18. Backtracking Search With Ordering and Early Failure Detection Call: Recursive-Backtracking({}, csp) If (inference(csp, var, assignment) == failure) return failure # Check consistency here (called “inference”) and backtrack if we know that the branch will lead to failure.
  • 19. Local search for CSPs Local search can attempt to reduce unsatisfied constraints by the min-conflicts heuristic: 1. Select a conflicted variable and 2. Choose a new value that produces violates the fewest constraints (local improvement step) 3. Repeat till all constraints are met. Local search is often very effective for CSPs. CSP algorithms • Allow incomplete states. • States must satisfy all constraints. Local Search works only with • Only “complete” states (all variables assigned) • Allows states with unsatisfied constraints. vs.
  • 20. Summary • CSPs are a special type of search problem: • States are structured and defined by a set of variables and values assignments • Variables can be unassigned • Goal test defined by • Consistency with constraints • Completeness of assignment • Backtracking search = depth-first search where a successor state is generated by a consistent value assignment to a single unassigned variable • Starts with {} and only considers consistent assignments. • Variable ordering and value selection heuristics can help significantly • Forward checking prevents assignments that guarantee later failure • Local search can be used to search the space of all complete assignments for consistent assignments = min-conflicts heuristic.