Constraint Satisfaction
Constraint Satisfaction
• Standard search problem: state is a "black box“ – any data structure that
supports successor function and goal test. The state is a number.
• SSP: Number
• CSP: Variables+ Values
X: It is a set of variables.
D: It is a set of domains where the variables reside. There is a specific domain for
each variable.
C: It is a set of constraints which are followed by the set of variables.
• 1. Graph Coloring: The problem where the constraint is that no adjacent sides
can have the same color.
2. Sudoku Playing: The gameplay where the constraint is that no
number from 0-9 can be repeated in the same row or column.
Variables: 81 variables
A1, A2, A3, …, I7, I8, I9
Letters index rows, top to bottom
Digits index columns, left to right
Domains: The nine positive digits
A1 {1, 2, 3, 4, 5, 6, 7, 8, 9}
Etc.
Constraints: 27 Alldiff constraints
Alldiff(A1, A2, A3, A4, A5, A6, A7,
A8, A9)
Etc.
3. Crossword: In crossword problem, the constraint is that there should be the
correct formation of the words, and it should be meaningful.
• Preferences/ Soft constraints – Need not be satisfied but you get credit for satisfy the
constraint.
• Works in the real work.
Backtracking search
• Start from an empty solution and set the variables one by one until we assign
values to all.
• Condition:
• => Only need to consider assignments to a single variable at each node.
Backtracking example – Order of variable assignment to nodes
Backtracking example
Backtracking example
Backtracking example
Improving backtracking
• Ordering:
Which variable should be assigned next.
The order in which it should be tried.
• Filtering:
To detect inevitable failure (bad choice) early.
• Structure:
Emphasize more on the problem structure.
Backtrack with Heuristics
• 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
•
Constraint propagation
• Forward checking propagates information from assigned to unassigned
variables, but doesn't provide early detection for all failures:
9 9
2 2
1 2 1
Variables: A,B,C
Domain: 0,1,2,3,4,5,6,7,8,9
CSP as a standard search problem
• Incremental formulation
T H I S T O M S E N D
I S + N A G + MO R E +
H E RE GOAT MONEY
Link: https://prepinsta.com/infosys/logical/cryptarithmetic/