SlideShare a Scribd company logo
Constraint Satisfaction Problems (CSP)
Constraint satisfaction problem
A constraint satisfaction problem (CSP) requires a value, selected
from a given finite domain, to be assigned to each variable in
the problem, so that all constraints relating the variables are satisfied.
Many combinatorial problems in operational research, such as
scheduling and timetabling, can be formulated as CSPs.
2
Constraint satisfaction problem
CSP is one of the standard search problem where instead of saying state
is black box, we say state is defined by variables and values.
• 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
3
Varieties of CSPs
 Discrete variables
• Finite domains:
• n variables, domain size d  O(d n) complete assignments
• e.g., 3-SAT (NP-complete)
• Infinite domains:
• integers, strings, etc.
• e.g., job scheduling, variables are start/end days for each job
• need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3
 Continuous variables
• e.g., start/end times for Hubble Space Telescope observations
• linear constraints solvable in polynomial time by linear programming
4
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., SA ≠ WA ≠ NT
Preferences (Soft Constraints): e.g. red is better than green. Need not be satisfied but
you get credit for satisfying them.
Constraint Optimization Problems.
5
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
 Hardware configuration
 Floor planning
Notice that many real-world problems involve real-valued variables.
6
Examples of CSPs
1. Graph/ Map Coloring
2. Sudoku Problems
3. Cryptarithmetic Problems
4. 4- Queen Problems
5. Puzzles etc.
7
Example: Cryptarithmetic
Cryptarithmetic: is a type of constraint satisfaction problem in which
each alphabet and symbol is associated with unique digit.
Rules:
1. Each alphabet has unique digit
2. Digit ranges from 0- 9
3. Only one carry should be found
4. Can be solved from both sides.
8
Example: Cryptarithmetic
+
S E N D
M O R E
M O N E Y
9
Constraints
1. Every letter must have a digit.
2. Each letter must have different digit
𝑉𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠, 𝑋 = 0 {𝑆, 𝐸, 𝑁, 𝐷, 𝑀, 𝑂, 𝑅, 𝑌0}
𝐷𝑜𝑚𝑎𝑖𝑛𝑠, 𝐷 (𝑒𝑥𝑐𝑒𝑝𝑡 𝑆 & 𝑀) = {0,1, 2, 3, 4, 5, 6, 7, 8, 9}
𝐶𝑜𝑛𝑠𝑡𝑟𝑎𝑖𝑛𝑡𝑠: 𝐴𝑙𝑙𝑑𝑖𝑓(𝑆, 𝐸, 𝑁, 𝐷, 𝑀, 𝑂, 𝑅, 𝑌)0
𝐷𝑜𝑚𝑎𝑖𝑛𝑠, 𝐷 (𝑆 & 𝑀) = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Example: Cryptarithmetic
10
+
+
S E N D
M O R E
M O N E Y
Character Code
S
E
N
D
M
O
R
Y
11
+
1
+
S E N D
M O R E
M O N E Y
Character Code
S
E
N
D
M
O
R
Y
12
+ 1
1
+
S E N D
M O R E
M O N E Y
Character Code
S
E
N
D
M 1
O
R
Y
13
+
9
1
1 0
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O
R
Y
14
+
9
1 0
1 0
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O 0
R
Y
15
+
9 ?
1 0
1 0 N
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O 0
R
Y
E + 0 = N
16
+
9 E
1 0
1 0 N
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O 0
R
Y
1 CARRY FROM HERE
Expression: E + 1 = N ( N & E differ by 1 )
17
+
9 E
1 0
1 0 N
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O 0
R
Y
1
Expression:
1. E + 1 = N [ N & E differ by 1 ]
2. N + R (+1) = E + 10 [ (+1) will be considered only if needed ]
18
+
9 E
1 0
1 0 N
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O 0
R 8
Y
1
Expression:
1. E + 1 = N [ N & E differ by 1 ]
2. N + R (+1) = E + 10 [ (+1) will be considered only if needed ]
Substituting the values:
E + 1 + R (+1) = E + 10
Hence, R (+1) = 9
If we do not consider carry then
R must be 9 but which is not
possible because 9 has already
taken, so R might be 8.
19
+
9 E
1 0 8
1 0 N
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E
N
D
M 1
O 0
R 8
Y
1 1
Now D+E= Y, has to be such that generates carry, D+E should be
sum up to more than 11 because Y can not be 0 or 1 as they have
already been taken, so to get that, the possibilities are 7+5 or 7+6 and
so on.
So, if we take D = 7, E = 5, Hence Y = 2
20
+
9 5 7
1 0 8 5
1 0 N 2
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E 5
N
D 7
M 1
O 0
R 8
Y 2
1 1
Expression:
1. E + 1 = N
21
+
9 5 6 7
1 0 8 5
1 0 6 4 2
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E 5
N 6
D 7
M 1
O 0
R 8
Y 2
1 1
Hence N = 6
22
+
9 5 6 7
1 0 8 5
1 0 6 4 2
+
S E N D
M O R E
M O N E Y
Character Code
S 9
E 5
N 6
D 7
M 1
O 0
R 8
Y 2
Example: Sudoku
𝑋1 𝑋2 𝑋3
𝑋4 𝑋5 𝑋6
𝑋7 𝑋8 𝑋9
23
Constraints
• Each box contains only unique values
• Same values can not be on multiple place on
sudoku box
𝑉𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 ∶ 𝑋𝑖 = {𝑋1, 𝑋2, 𝑋3, 𝑋4, 𝑋5, 𝑋6, 𝑋7, 𝑋8, 𝑋9}
𝐷𝑜𝑚𝑎𝑖𝑛𝑠: 𝐷𝑖 = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Solution of this CSP is : {𝑋𝑖} = {𝐷𝑖}
𝐶𝑜𝑛𝑠𝑡𝑟𝑎𝑖𝑛𝑡𝑠: 𝐴𝑙𝑙𝑑𝑖𝑓(1, 2, 3, 4, 5, 6, 7, 8, 9)0
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
24
Example: Map-Coloring
25
Variables WA, NT, Q, NSW, V, SA, T
Domains Di = {red, green, blue}
Constraints: adjacent regions must have different colors. e.g., WA ≠ NT
Example: Map-Coloring
26
Solutions are complete and consistent assignments, e.g., WA = red,
NT = green, Q = red, NSW = green, V = red, SA = blue, T = green
Thank You
27

More Related Content

PDF
Hill Climbing Algorithm in Artificial Intelligence
PPT
5 csp
PDF
AI 7 | Constraint Satisfaction Problem
PPTX
Forward checking
PPTX
Certinity Factor and Dempster-shafer theory .pptx
PDF
AI 5 | Local Search
PDF
AI_unit IV Full Notes.pdf
PPTX
A star algorithms
Hill Climbing Algorithm in Artificial Intelligence
5 csp
AI 7 | Constraint Satisfaction Problem
Forward checking
Certinity Factor and Dempster-shafer theory .pptx
AI 5 | Local Search
AI_unit IV Full Notes.pdf
A star algorithms

What's hot (20)

PPTX
Chess board problem(divide and conquer)
PPTX
Recognition-of-tokens
PPTX
Constraint satisfaction problems (csp)
PPT
Heuristic Search Techniques Unit -II.ppt
PPT
Randomized algorithms ver 1.0
PDF
Formal Languages and Automata Theory Unit 1
DOC
Chapter 4 (final)
PPTX
Lecture 21 problem reduction search ao star search
PPTX
Register allocation and assignment
PPTX
Performance analysis(Time & Space Complexity)
PDF
I.BEST FIRST SEARCH IN AI
PPTX
Ambiguous & Unambiguous Grammar
PDF
UNIT - I PROBLEM SOLVING AGENTS and EXAMPLES.pptx.pdf
PPT
Sum of subsets problem by backtracking 
PDF
A* Search Algorithm
PPTX
Control Strategies in AI
PPTX
Artificial Intelligence Searching Techniques
PPTX
Greedy Algorithm - Knapsack Problem
PPTX
Asymptotic Notation
PPTX
Problem solving agents
Chess board problem(divide and conquer)
Recognition-of-tokens
Constraint satisfaction problems (csp)
Heuristic Search Techniques Unit -II.ppt
Randomized algorithms ver 1.0
Formal Languages and Automata Theory Unit 1
Chapter 4 (final)
Lecture 21 problem reduction search ao star search
Register allocation and assignment
Performance analysis(Time & Space Complexity)
I.BEST FIRST SEARCH IN AI
Ambiguous & Unambiguous Grammar
UNIT - I PROBLEM SOLVING AGENTS and EXAMPLES.pptx.pdf
Sum of subsets problem by backtracking 
A* Search Algorithm
Control Strategies in AI
Artificial Intelligence Searching Techniques
Greedy Algorithm - Knapsack Problem
Asymptotic Notation
Problem solving agents
Ad

Similar to Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Queen, Sudoku (20)

PPT
presentation related to artificial intelligence.ppt
PPT
presentation on artificial intelligence autosaved
PDF
Artificial Intelligence JNTUH Syllabusss
PPT
ConstraintSatisfaction.ppt
PPTX
AI UNIT 3 PPTs AI UNIT 3 PPT AI UNIT 3 PPT AI UNIT 3 PPT.pptx
PPTX
Artificial Intellligence Constraint Satisfaction Problem.pptx
PPTX
CSP.pptx
PPTX
Constraint Satisfaction Problems - Copy.pptx
PDF
Constraint Satisfaction.pdf
PPTX
Constraint Satisfaction Problems_ AI2025
PPTX
AI_Session 17 CSP.pptx
PPTX
AI3391 Artificial Intelligence Session 21 CSP.pptx
PDF
Combinatorial Problems2
PPT
modeling.ppt
PDF
Ai lecture 11(unit02)
PPT
Sudoku
PPTX
AI3391 Artificial intelligence Session 22 Cryptarithmetic problem.pptx
PPTX
CS415 - Lecture 11 - CSPs I.pptx
PDF
Ai lecture 9(unit02)
presentation related to artificial intelligence.ppt
presentation on artificial intelligence autosaved
Artificial Intelligence JNTUH Syllabusss
ConstraintSatisfaction.ppt
AI UNIT 3 PPTs AI UNIT 3 PPT AI UNIT 3 PPT AI UNIT 3 PPT.pptx
Artificial Intellligence Constraint Satisfaction Problem.pptx
CSP.pptx
Constraint Satisfaction Problems - Copy.pptx
Constraint Satisfaction.pdf
Constraint Satisfaction Problems_ AI2025
AI_Session 17 CSP.pptx
AI3391 Artificial Intelligence Session 21 CSP.pptx
Combinatorial Problems2
modeling.ppt
Ai lecture 11(unit02)
Sudoku
AI3391 Artificial intelligence Session 22 Cryptarithmetic problem.pptx
CS415 - Lecture 11 - CSPs I.pptx
Ai lecture 9(unit02)
Ad

More from Mahbubur Rahman (9)

PPTX
Randomized Algorithm- Advanced Algorithm
PPTX
Cloudonomics in Advanced Cloud Computing
PPTX
Geographic Routing in WSN
PPTX
Streaming Stored Video- Computer Networking
PPTX
Random Oracle Model & Hashing - Cryptography & Network Security
PPTX
Modern Block Cipher- Modern Symmetric-Key Cipher
PPT
Ll(1) Parser in Compilers
PPTX
Web Server And Database Server
DOCX
LEX & YACC
Randomized Algorithm- Advanced Algorithm
Cloudonomics in Advanced Cloud Computing
Geographic Routing in WSN
Streaming Stored Video- Computer Networking
Random Oracle Model & Hashing - Cryptography & Network Security
Modern Block Cipher- Modern Symmetric-Key Cipher
Ll(1) Parser in Compilers
Web Server And Database Server
LEX & YACC

Recently uploaded (20)

PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
Artificial Intelligence
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Current and future trends in Computer Vision.pptx
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
PPT on Performance Review to get promotions
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Well-logging-methods_new................
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Safety Seminar civil to be ensured for safe working.
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Categorization of Factors Affecting Classification Algorithms Selection
Artificial Intelligence
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Current and future trends in Computer Vision.pptx
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Geodesy 1.pptx...............................................
CYBER-CRIMES AND SECURITY A guide to understanding
Fundamentals of safety and accident prevention -final (1).pptx
Sustainable Sites - Green Building Construction
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPT on Performance Review to get promotions
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Well-logging-methods_new................

Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Queen, Sudoku

  • 2. Constraint satisfaction problem A constraint satisfaction problem (CSP) requires a value, selected from a given finite domain, to be assigned to each variable in the problem, so that all constraints relating the variables are satisfied. Many combinatorial problems in operational research, such as scheduling and timetabling, can be formulated as CSPs. 2
  • 3. Constraint satisfaction problem CSP is one of the standard search problem where instead of saying state is black box, we say state is defined by variables and values. • 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 3
  • 4. Varieties of CSPs  Discrete variables • Finite domains: • n variables, domain size d  O(d n) complete assignments • e.g., 3-SAT (NP-complete) • Infinite domains: • integers, strings, etc. • e.g., job scheduling, variables are start/end days for each job • need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3  Continuous variables • e.g., start/end times for Hubble Space Telescope observations • linear constraints solvable in polynomial time by linear programming 4
  • 5. 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., SA ≠ WA ≠ NT Preferences (Soft Constraints): e.g. red is better than green. Need not be satisfied but you get credit for satisfying them. Constraint Optimization Problems. 5
  • 6. 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  Hardware configuration  Floor planning Notice that many real-world problems involve real-valued variables. 6
  • 7. Examples of CSPs 1. Graph/ Map Coloring 2. Sudoku Problems 3. Cryptarithmetic Problems 4. 4- Queen Problems 5. Puzzles etc. 7
  • 8. Example: Cryptarithmetic Cryptarithmetic: is a type of constraint satisfaction problem in which each alphabet and symbol is associated with unique digit. Rules: 1. Each alphabet has unique digit 2. Digit ranges from 0- 9 3. Only one carry should be found 4. Can be solved from both sides. 8
  • 9. Example: Cryptarithmetic + S E N D M O R E M O N E Y 9 Constraints 1. Every letter must have a digit. 2. Each letter must have different digit 𝑉𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠, 𝑋 = 0 {𝑆, 𝐸, 𝑁, 𝐷, 𝑀, 𝑂, 𝑅, 𝑌0} 𝐷𝑜𝑚𝑎𝑖𝑛𝑠, 𝐷 (𝑒𝑥𝑐𝑒𝑝𝑡 𝑆 & 𝑀) = {0,1, 2, 3, 4, 5, 6, 7, 8, 9} 𝐶𝑜𝑛𝑠𝑡𝑟𝑎𝑖𝑛𝑡𝑠: 𝐴𝑙𝑙𝑑𝑖𝑓(𝑆, 𝐸, 𝑁, 𝐷, 𝑀, 𝑂, 𝑅, 𝑌)0 𝐷𝑜𝑚𝑎𝑖𝑛𝑠, 𝐷 (𝑆 & 𝑀) = {1, 2, 3, 4, 5, 6, 7, 8, 9}
  • 10. Example: Cryptarithmetic 10 + + S E N D M O R E M O N E Y Character Code S E N D M O R Y
  • 11. 11 + 1 + S E N D M O R E M O N E Y Character Code S E N D M O R Y
  • 12. 12 + 1 1 + S E N D M O R E M O N E Y Character Code S E N D M 1 O R Y
  • 13. 13 + 9 1 1 0 + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O R Y
  • 14. 14 + 9 1 0 1 0 + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O 0 R Y
  • 15. 15 + 9 ? 1 0 1 0 N + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O 0 R Y E + 0 = N
  • 16. 16 + 9 E 1 0 1 0 N + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O 0 R Y 1 CARRY FROM HERE Expression: E + 1 = N ( N & E differ by 1 )
  • 17. 17 + 9 E 1 0 1 0 N + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O 0 R Y 1 Expression: 1. E + 1 = N [ N & E differ by 1 ] 2. N + R (+1) = E + 10 [ (+1) will be considered only if needed ]
  • 18. 18 + 9 E 1 0 1 0 N + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O 0 R 8 Y 1 Expression: 1. E + 1 = N [ N & E differ by 1 ] 2. N + R (+1) = E + 10 [ (+1) will be considered only if needed ] Substituting the values: E + 1 + R (+1) = E + 10 Hence, R (+1) = 9 If we do not consider carry then R must be 9 but which is not possible because 9 has already taken, so R might be 8.
  • 19. 19 + 9 E 1 0 8 1 0 N + S E N D M O R E M O N E Y Character Code S 9 E N D M 1 O 0 R 8 Y 1 1 Now D+E= Y, has to be such that generates carry, D+E should be sum up to more than 11 because Y can not be 0 or 1 as they have already been taken, so to get that, the possibilities are 7+5 or 7+6 and so on. So, if we take D = 7, E = 5, Hence Y = 2
  • 20. 20 + 9 5 7 1 0 8 5 1 0 N 2 + S E N D M O R E M O N E Y Character Code S 9 E 5 N D 7 M 1 O 0 R 8 Y 2 1 1 Expression: 1. E + 1 = N
  • 21. 21 + 9 5 6 7 1 0 8 5 1 0 6 4 2 + S E N D M O R E M O N E Y Character Code S 9 E 5 N 6 D 7 M 1 O 0 R 8 Y 2 1 1 Hence N = 6
  • 22. 22 + 9 5 6 7 1 0 8 5 1 0 6 4 2 + S E N D M O R E M O N E Y Character Code S 9 E 5 N 6 D 7 M 1 O 0 R 8 Y 2
  • 23. Example: Sudoku 𝑋1 𝑋2 𝑋3 𝑋4 𝑋5 𝑋6 𝑋7 𝑋8 𝑋9 23 Constraints • Each box contains only unique values • Same values can not be on multiple place on sudoku box 𝑉𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 ∶ 𝑋𝑖 = {𝑋1, 𝑋2, 𝑋3, 𝑋4, 𝑋5, 𝑋6, 𝑋7, 𝑋8, 𝑋9} 𝐷𝑜𝑚𝑎𝑖𝑛𝑠: 𝐷𝑖 = {1, 2, 3, 4, 5, 6, 7, 8, 9} Solution of this CSP is : {𝑋𝑖} = {𝐷𝑖} 𝐶𝑜𝑛𝑠𝑡𝑟𝑎𝑖𝑛𝑡𝑠: 𝐴𝑙𝑙𝑑𝑖𝑓(1, 2, 3, 4, 5, 6, 7, 8, 9)0
  • 24. 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 24
  • 25. Example: Map-Coloring 25 Variables WA, NT, Q, NSW, V, SA, T Domains Di = {red, green, blue} Constraints: adjacent regions must have different colors. e.g., WA ≠ NT
  • 26. Example: Map-Coloring 26 Solutions are complete and consistent assignments, e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green