# Lecture 5 Constraint Satisfaction by nml23533

VIEWS: 148 PAGES: 35

• pg 1
```									   Lecture 5: Constraint Satisfaction

Definition and examples
Heshaam Faili
Properties of CSP problems
hfaili@ece.ut.ac.ir            Heuristics
University of Tehran       arc-consistency checking
heuristic repair
most-constrained first
Constraint Satisfaction
Problems
   Many problems can be formulated as finding a
solution, possibly optimal, that satisfies a set of
constraints.
    built a time table for the next semester with the
minimum number of conflicts
   schedule air crew assignments so that pilots don’t fly
too many hours, have evenly-spaced breaks, …
   find a 0/1 assignment to a propositional formula
   8-queen problem, crypto arithmetic

2
CSP as a search problem (1)
   State:
   a set of variables x1, x2, …,xn
   variable domains D1, D2 …Dn
   state vector (x1, x2, x3, … xn) with instantiated and
uninstantiated variables
   Rule: constraints relating the variables
   xi  xj,  xi = 1, min f(x1, x2, …,xn)
   Start state: vector of uninstantiated variables
   Goal state: instantiated vector that satisfies all
the constraints
3
Examples of CSP formulation
• Cryptoarithmetic problem
FO RTY               29786         Solution
+    TEN            +    850        F=2, O=9
R=7, T=8
+    TEN            +    850        Y=6, E=5
S I XTY              31486         N=0, I=1, X=4

• 8-queens problem     • Time-table schedule
Mon Tue Wed Thu Fri
8
9
10
11
4
CSP and Constraint Graph

5
CSP as a search problem (2)
   Simplest form: discrete and finite domain
   For n variables and domain size d the possible assignments are O(dn)
   Boolean CSP: domains are boolean, like 3SAT , special case of NP-
complete
   Infinite domain: no exact solution can be found
   Linear constraints
   Non-linear constraints
   Continuous domains:
   The best-known category is linear programming
   Constraints are linear inequalities forming a convex region
   Constraints:
   Unary: involve only one variable: can be eliminated by remove any value
violate the constraint from the domain of that variable
   Binary: involves two variables (like 8-queen)
   Higher-order : like crypt arithmetic

6
Higher-order Constraints
   Can be represented by a constraints hyper-graph
   prove, every higher-order, finite-domain constraint can be
reduced to a set of binary constraints if enough auxiliary
variables are introduced.

7
Backtracking in CSP
   For n variables with d value in each domain
   Branching factor for level 1 is nd, level 2 is (n-1)d, level 3 is (n-2)d,
…
   Tree has n!dn leaves while there are only dn possible assignments
   Commutativity: if the order of application of any given set of
actions has no effect on the outcome.
   CSPs are commutative
   all CSP search algorithms generate successors by considering
possible assignments for only a single variable at each node in the
search tree
   In root node of Australia region coloring: we choice between SA =
red, SA = green, and SA = blue, and we never choose between SA
= red and WA = blue.
   The number of leaves are dn

8
CSP as a search problem
   Search strategy
1. pick an uninstantiated variable, pick a value from its
domain, check if all constraints are satisfied
2. if constraints are satisfied, continue search
recursively
3. else, backtrack: go back to previous decision and
make another choice
   Size of search tree:     bd
   d = n, number of variables
   b = max Di when only one variable at a time is
9
Backtracking Search

10
CSP search example

11
CSP search example
C1 C2 C3                 
S E N D
+
M O R E
M=1
M O N E Y
O=0   O=2     O=3

N=2
S32D
E=3                 10R3
Conflict!   12
1023Y
CSP problem characteristics (1)
   Special case of a search problem
   Domains can be discrete or continuous
   The order in which the constraints are
satisfied does not matter.
   The order in which variables and their
values are picked makes a big difference!

13
CSP problem characteristics (2)
   The goal test is decomposed into a set of
constraints on variables, rather than a
single black box
   When sets of variables are independent
(no constraints between them) the
problem is decomposable and sub-
problems can be solved independently.
   A each step we must check for
consistency. We need constraint
propagation methods!                        14
CSP problem characteristics (3)
   Answering the following questions are
important key:
   Which variable should be assigned next, and in
what order should its values be tried?
   What are the implications of the current variable
assignments for the other unassigned variables?
   When a path fails—that is, a state is reached in
which a variable has no legal values— can the
search avoid repeating this failure in subsequent
paths?

15
Comparison of various CSP algorithms

16
Variable and value ordering
   Pick values for the minimum remaining
values (MRV) or most constrained
variables or first fail principle
   choosing the variable with the fewest "legal" value
   those with smaller domains and which appear in
more constraints.
   The rationale: those leave fewer choices and focus
the search
   Improve the search from 3 til 3000 times
better than simple
17
Variable and value ordering
   MRV doesn’t help in choosing the first
variable
   Degree heuristic: attempts to reduce the
BF in feature by selecting the variables that
is involved in the largest number of
constraints on other unassigned variables
   SA on region coloring example

18
Value ordering
   least-constraining-value: prefers the
value that rules out the fewest choices for the
neighboring variables in the constraint
   In the previous coloring problem:
   WA = red and NT = green, Q is better to assign
red that blue
   if we are trying to find all the solutions to a
problem, not just the first one, then the
ordering does not matter because we have to
consider every value anyway.
19
Propagating information
through constraints (1)
   Forward checking: delete values from
domains as the assignments are made.
When a domain becomes empty, abort.
Often more efficient than backtracking

20
Forward checking example

21
Propagating information
through constraints (2)
   Forward Checking: doesn't detect all of inconsistencies.
   WA = red, Q=green => NT = SA = blue (this inconsistency doesn’t
detected)
   Arc-consistency: a state is arc-consistent if every variable has a
value in its domain that is consistent with each of the constraints
of that variable. This is a form of constraint propagation.
   Arc-consistency provides a fast method of constraint propagation
that is substantially stronger than forward checking.
   arc-consistency is directed arc in constraint graph
   (SA, NSW) is consistent while (NSW,SA) is not consistent
   Complexity: O(n2d3) for binary CSP
   Binary CSP has at most O(n2) arcs
   Each arc (Xi,Xk) can be inserted on the agenda only d times: Xi has at
most d values to delete
22
   Checking consistency of an arc can be done in O(d2)
Arc-Consistency

AC-3 can not find harder the
inconsistency
(WA=red, NSW=red)
Need more concepts

23
CSP terminology
   Label <xi, a>
   Compound Label { <xi, a> }
   K-Constraint
   Modeling 8-Queen problem:
   Q1,Q2, …,Q8 in [a,b,…,h]
   Qx  Qy , |Qx-Qy|  |x-y|

24
Important Concepts
   K-Satisfiable
   K-Consistency
   K=1: node consistency
   K>1: for each K-1 satisfiable variable set can add
the Kth variable with consistent value and no
change in the previous K-1 variable values
   K-strongly consistent
A {red, green}         3-Consistent
But not 2-Consistent

C{red}        B{red}
25
Handling special constraints
   some problem-specific constraints are used much in different
problems
   AllDiff constraints says that all variables should be different
   If n variables with m values and n>m, the constraints should not
be satisfied
   Use the following idea to develop a method:
   First, remove any variable in the constraint that has a singleton
domain, and delete that variable's value from the domains of the
remaining variables.
   Repeat as long as there are singleton variables.
   If at any point an empty domain is produced or there are more
variables than domain values left, then an inconsistency has been
detected.
   By using the above method, the inconsistency (WA=red,
NSW=red) can be detected.

26
Handling special constraints
   Resource constraints: the most important higher-order
constraints
   Atmost constraints:(A0, PA1, PA2, PA3, PA4).
   Checking the sum of minimum values of current domains (in each step of
procedure)
   For example, let's suppose there are two flights, 271 and 272,
for which the planes have capacities 165 and 385, respectively.
The initial domains for the numbers of passengers on each flight
are then
   Flight271  [0,165] and Flight272  [0, 385]
   Now suppose we have the additional constraint that the two
flights together must carry 420 people: Flight271 + Flight272 
[420,420]. Propagating bounds constraints, we reduce the
domains to
   Flight271  [35,165] and Flight272  [255, 385]

27
CSP heuristics: example
C1 C2 C3 C4                  
S E N D
+
M O R E
M=1
C1 = 1
M O N E Y                                    C2 + S + 1 = O
O=0     O=2      O=3      C2 + S + 1 = 1
C3 + E + 0 = N
C4 + N + R = E
N=2

Conflict is detected as
E=3
soon as the assignement
28
Graph of variables
dependencies
Y
Constraints
X+Y=Z                        W
X-Z<7
Y = Z           X
X-W=3                    Z
U-V=0

Domains
DX = {0, 1, 2}           V       U
DY = {0, … 10}
….                                   29
Intelligent backtracking:
looking backward
   chronological backtracking: Simple BT
   More intelligent: use conflict set
   Backjumping method: backtrack to the
most recent variable in conflict set

30
Min-conflict strategy on 8-
queens

31
Important concept (constraint graph)
   Graph Order
   Node width
   Graph Order width
   Graph Width
   Value ordering for CSP search in the
minimum Graph order width
   If the level of strong consistency is greater
than the width of constraint graph, the search
for solution tuple is backtrack free

32
Search Strategies
(Haralick & Elliot 1980)
   Standard Backtracking
   Fully Looking Forward
   Forward Checking
   Backchecking
   BackMarking

33
CSP problems at large
   An area of great economic importance
   scheduling, production, etc.
   Closely related to optimization problems
   integer programming
   multiobjective optimization
   Large body of literature in different
areas: AI, CS, Operations Research,
Mathematics, …
34
?
35

```
To top