Cs3491 - Aiml - Unit I - Constraint Satisfaction Problems
Cs3491 - Aiml - Unit I - Constraint Satisfaction Problems
Engineering
Regulation 21
Semester: III
K.Sumithra Devi
Assistant Professor
CSE
UNIT I PROBLEM SOLVING - CONSTRAINT SATISFACTION PROBLEMS
K3
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
• The practical applications of CSPs are very straightforward. CSPs are very
good for solving general temporal and combinatorial problems, among
other things. The following are examples where constraint programming
has been successfully applied in various other fields:
• - Operations Research (scheduling, timetabling)
- Bioinformatics (DNA sequencing)
- Electrical engineering (circuit layout-ing)
- Telecommunications (CTVR @ 4C)
- Hubbell telescope/Satellite scheduling
• Constraint graph:
• Discrete variables
• Continuous variables
• e.g. building an airline schedule or class schedule.
• Assignment problems
• e.g., who teaches what class
• Timetabling problems
• e.g., which class is offered when and where?
• Transportation scheduling
• Factory scheduling
• Incremental formulation
• Path cost: constant cost for every step (not really relevant)
• end up with n!dn leaves even though there are only dn complete assignments!
• Chooses values for one variable at a time and backtracks when a variable has no legal
values left to assign.
• Uninformed algorithm
• No good general performance (see table p. 143)
• For CSPS, general-purpose methods can give large gains in speed, e.g.,
• Which variable should be assigned next?
• In what order should its values be tried?
• Can we detect inevitable failure early?
• Can we take advantage of problem structure?
var SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp)
• Heuristic Rule: select variable that is involved in the largest number of constraints on other
unassigned variables.
• Forward checking idea: keep track of remaining legal values for unassigned variables.
• Assign {WA=red}
• Assign {Q=green}
• If V is assigned blue
• FC has detected that partial assignment is inconsistent with the constraints and backtracking can occur.
USA: 4 coloring
n-queens: n = 2 to 50
Zebra: see exercise 5.13
• Solving CSPs with combination of heuristics plus forward checking is more efficient than
either approach alone
• Techniques like CP and FC are in effect eliminating parts of the search space
• Somewhat complementary to search
• An Arc X Y is consistent if
for every value x of X there is some value y consistent with x
(note that this is a directed property)
SA NSW is consistent if
SA=blue and NSW=red
• X Y is consistent if
for every value x of X there is some value y consistent with x
• NSW SA is consistent if
NSW=red and SA=blue
NSW=blue and SA=???
• SA NT is not consistent
• and cannot be made consistent
• Trade-off
• Requires some overhead to do, but generally more effective than direct search
• In effect it can eliminate large (inconsistent) parts of the state space more
effectively than search can
[R]
[R,B,G] [R,B,G]
• This is a propagation algorithm. It’s like sending messages to neighbors on the graph. How
do we schedule these messages?
• Every time a domain changes, all incoming messages need to be re-sent. Repeat until
convergence no message will change any domains.
• Since we only remove values from domains when they can never be part of a solution, an
empty domain means no solution possible at all back out of that branch.
• Forward checking is simply sending messages into a variable that just got its value assigned.
First step of arc-consistency.
• A CSP is k-consistent if for any set of k-1 variables and for any consistent assignment to
those variables, a consistent value can always be assigned to any kth variable.
• E.g. 1-consistency = node-consistency
• E.g. 2-consistency = arc-consistency
• E.g. 3-consistency = path-consistency
• Strongly k-consistent:
• k-consistent for all values {k, k-1, …2, 1}
• No “free lunch”
• In worst case n-consistency takes exponential time
• Intelligent backtracking
• Standard form is chronological backtracking i.e. try different value for preceding variable.
• More intelligent, backtrack to conflict set.
• Set of variables that caused the failure or set of previously assigned variables that are
connected to X by constraints.
• Backjumping moves back to most recent element of the conflict set.
• Forward checking can be used to determine conflict set.
• For CSPs
• allow states with unsatisfied constraints (unlike backtracking)
• operators reassign variable values
• hill-climbing with n-queens is an example
• The algorithm moves the queen to the min-conflict square breaking ties randomly.
USA: 4 coloring
n-queens: n = 2 to 50
Zebra: see exercise 5.13
• Why?
• n-queens is easy for local search because of the relatively high density of solutions in
state-space
• Theorem:
• if a constraint graph has no loops then the CSP can be solved in O(nd 2) time
• linear in the number of variables!
• Backward Pass
• For j from n down to 2, apply arc consistency to arc [Parent(Xj), Xj) ]
• Remove values from Parent(Xj) if needed
• Forward Pass
• For j from 1 to n assign Xj consistently with Parent(Xj )
G B
Backward Pass B B
(constraint R B R
G R G B
propagation) G G
Backward Pass B B
(constraint R B R
G R G B
propagation) G G
Forward Pass B G R R G B
(assignment)
• Backward pass
• n arc checks
• Each has complexity d2 at worst
• Forward pass
• n variable assignments, O(nd)
Algorithm works because if the backward pass succeeds, then every variable
by definition has a legal assignment in the forward pass
2 general approaches
• Choose a subset S of variables from the graph so that graph without S is a tree
• S = “cycle cutset”
• If two variables are connected in the original problem, they must appear
together (with the constraint) in at least one subproblem
• Now use the tree CSP algorithm to solve the constraints connecting the
subproblems
• Declare a subproblem a root node, create tree
• Backward and forward passes
• Finding the optimal tree-width of a graph is NP-hard, but good heuristics exist.
• CSPs
• special kind of problem: states defined by values of a fixed set of variables, goal test defined by
constraints on variable values
• Heuristics
• Variable ordering and value selection heuristics help significantly
• Constraint propagation does additional work to constrain values and detect inconsistencies
• Works effectively when combined with heuristics