0% found this document useful (0 votes)
31 views27 pages

Constraint Satisfaction

The document discusses constraint satisfaction problems (CSPs). CSPs involve solving problems under certain constraints or rules. A CSP is defined by a set of variables, their possible domains/values, and constraints restricting allowable value combinations. CSPs can model problems like graph coloring, Sudoku, and crosswords. Backtracking search is commonly used to systematically assign values to variables while checking constraints. Techniques like heuristics, forward checking, and constraint propagation can improve search efficiency.

Uploaded by

Raghu Somu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views27 pages

Constraint Satisfaction

The document discusses constraint satisfaction problems (CSPs). CSPs involve solving problems under certain constraints or rules. A CSP is defined by a set of variables, their possible domains/values, and constraints restricting allowable value combinations. CSPs can model problems like graph coloring, Sudoku, and crosswords. Backtracking search is commonly used to systematically assign values to variables while checking constraints. Techniques like heuristics, forward checking, and constraint propagation can improve search efficiency.

Uploaded by

Raghu Somu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Constraint Satisfaction Problem

Constraint satisfaction problems (CSPs)


• Solving a problem under certain constraints or rules.

• 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.

• More powerful than standard search algorithms –


Deeper understanding of the problem structure as well as its complexity.
CSP Problems
• Problems with some constraints while solving the problem.

• 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.

• Variables: Unblocked cells.


• Domains: The domain of each variable is the set
of letters of the alphabet.

• Constraints: For each vertical or horizontal


contiguous segment of unblocked cells, we add a
constraint between the cells in that segment,
constraining the letters assigned to the cells in that
segment to form a word that appears in the
dictionary.
Example: Map-Coloring

• Variables WA, NT, Q, NSW, V, SA, T


• Domains Di = {red,green,blue}
• Constraints: Two adjacent regions cannot have the same colours.
• e.g., WA ≠ NT, or (WA,NT) in {(red,green),(red,blue),(green,red),
(green,blue),(blue,red),(blue,green)}
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 – One of the possible
solution

A specific assignment to each variable so that all constraints are satisfied.


Constraint graph
• Constraint graph: Nodes are variables, Edge are
constraints.
• Binary CSP: Each constraint relates two variables

Two independent sub problems


Varieties of constraints- Based on variable
count
• 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

• 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.

• Depth-first search (DFS) for CSPs with single-variable assignments is called


backtracking search.
• 1. Select a variable.
• 2. Assign the variable to a node.
• 3. Check for constraint satisfaction. If not backtrack

• 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

• Solving CSPs (backtrack) with combination of heuristics plus


forward checking is more efficient than either approach
alone.

• Backtrack with Heuristics = Heuristics + Forward checking


• Forward Checking does not see all inconsistencies.

• Consider our map coloring search, after we have assigned


WA=red and Q=green
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

Constraint propagation
• Forward checking propagates information from assigned to unassigned
variables, but doesn't provide early detection for all failures:

• Forward checking = Assigned to unassigned


• Backtracking = Unassigned to assigned
• Constraint propagation algorithms repeatedly enforce constraints locally.
Crypt-Arithmetic problem

• Type of encryption problem in which the written message in an


alphabetical form which is easily readable and understandable is
converted into a numerical form which is neither easily readable or
understandable.
Constraints
Example
Example 2

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

• Initial State: the empty assignment {}

• Successor function: Assign a value to an unassigned variable


provided that it does not violate a constraint

• Goal test: the current assignment is complete


(by construction it is consistent)

• Path cost: constant cost for every step


Practice problems

The answer can not


be determined.

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/

You might also like