0% found this document useful (0 votes)
125 views

Constraint Satisfaction Problems

A constraint satisfaction problem (CSP) involves a set of variables that each have a domain of possible values, and a set of constraints that specify allowed value combinations for subsets of variables. The goal is to assign values to all variables in a way that satisfies the constraints. CSPs can model many real-world problems and are commonly solved using backtracking search with heuristics like most-constrained variable selection.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Constraint Satisfaction Problems

A constraint satisfaction problem (CSP) involves a set of variables that each have a domain of possible values, and a set of constraints that specify allowed value combinations for subsets of variables. The goal is to assign values to all variables in a way that satisfies the constraints. CSPs can model many real-world problems and are commonly solved using backtracking search with heuristics like most-constrained variable selection.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Constraint Satisfaction

Problems
Constraint satisfaction problems

• What is a CSP?
• Finite set of variables X1, X2, …, Xn
• Nonempty domain of possible values for each variable
D1, D2, … Dd
• Finite set of constraints C1, C2, …, Cm
• Each constraint Ci limits the values that variables can take, e.g., X1 ≠ X2
• A state is defined as an assignment of values to some or all variables.
• Consistent assignment: assignment does not violate the constraints.
Constraint satisfaction problems

• An assignment is complete when every variable is assigned a value.


• A solution to a CSP is a complete assignment that satisfies all
constraints.
• Some CSPs require a solution that maximizes an objective function.
• Applications:
• Scheduling problems
• Job scheduling
• Time table management
• Game playing
• Map coloring
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
• So (WA,NT) must be in {(red,green),(red,blue),(green,red), …}
Varieties of CSPs
• 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., crypt-arithmetic column constraints
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
Constraint graph
• Binary CSP: each constraint relates
two variables
• Constraint graph:
• nodes are variables
• arcs are constraints
• CSP benefits
• Standard representation pattern: variables with values
• Generic goal and successor functions
• Generic heuristics (no domain specific expertise).
• Graph can be used to simplify search.
• e.g. Tasmania is an independent subproblem.
CSP as a standard search problem

• A CSP can easily expressed as a standard search problem, as we have seen


• Initial State: the empty assignment {}.
• Successor function: Assign value to unassigned variable provided that there is not conflict.
• Goal test: the current assignment is complete.
• Path cost: a constant cost for every step.
• Solution is found at depth n , for n variables
• Hence depth first search can be used
Backtracking search
• Note that variable assignments are commutative
• Eg [ step 1: WA = red; step 2: NT = green ] equivalent to [ step 1: NT = green; step 2: 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


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?
• Heuristics:
1. Most constrained variable
2. Most constraining variable
3. Least constraining value
4. Forward checking
Heuristic 1: Most constrained variable
• Most constrained variable:
choose the variable with the fewest legal values

• a.k.a. minimum remaining values (MRV) heuristic


Heuristic 2: Most constraining variable
• Tie-breaker among most constrained variables
• Most constraining variable:
• choose the variable with the most constraints on remaining variables
• Also known as Degree Heuristic (DH)
Heuristic 3: Least constraining value
• Given a variable, choose the least constraining value:
• the one that rules out the fewest values in the remaining variables
Rationale for MRV, DH, LCV
• In all cases we want to enter the most promising branch, but we also want to
detect inevitable failure as soon as possible.
• MRV+DH: the variable that is most likely to cause failure in a branch is assigned first.
The variable must be assigned at some point, so if it is doomed to fail, we’d better
found out soon.
• LCV: tries to avoid failure by assigning values that leave maximal flexibility for the
remaining variables. We want our search to succeed as soon as possible, so given some
ordering, we want to find the successful branch.
Heuristic 4: Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values

• Edge & Arc consistency are variants


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
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 {1,2,3,4} {1,2,3,4}
2
3
4

X3 X4
{1,2,3,4} {1,2,3,4}
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 {1,2,3,4} {1,2,3,4}
2
3
4

X3 X4
{1,2,3,4} {1,2,3,4}
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 {1,2,3,4} { , ,3,4}
2
3
4

X3 X4
{ ,2, ,4} { ,2,3, }
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 {1,2,3,4} { , ,3,4}
2
3
4

X3 X4
{ ,2, ,4} { ,2,3, }
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 {1,2,3,4} { , ,3,4}
2
3
4
Backtrack!!!
X3 X4
{ , , , } { ,2, , }
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} {1,2,3,4}
2
3
4

X3 X4
{1,2,3,4} {1,2,3,4}
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4

X3 X4
{1, ,3, } {1, ,3,4}
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4

X3 X4
{1, ,3, } {1, ,3,4}
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4

X3 X4
{1, , , } {1, ,3, }
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4

X3 X4
{1, , , } {1, ,3, }
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4

X3 X4
{1, , , } { , ,3, }
Example: 4-Queens Problem

1 2 3 4 X1 X2
1 { ,2,3,4} { , , ,4}
2
3
4

X3 X4
{1, , , } { , ,3, }
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

You might also like