Constraint Propagation …
description
Transcript of Constraint Propagation …
![Page 1: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/1.jpg)
Constraint Propagation
(Where a better exploitation of the constraints further reduces the need to make decisions)
R&N: Chap. 5 + Chap. 24, p. 881-884
1
![Page 2: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/2.jpg)
Constraint Propagation …
… is the process of determining how the constraints and the possible values of one variable affect the possible values of other variables
It is an important form of “least-commitment” reasoning
2
![Page 3: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/3.jpg)
Forward checking is only on simple form of constraint
propagationWhen a pair (Xv) is added to assignment A do:
For each variable Y not in A do: For every constraint C relating Y to variables in A do:
Remove all values from Y’s domain that do not satisfy C
3
n = number of variables d = size of initial domains s = maximum number of constraints
involving a given variable (s n-1) Forward checking takes O(nsd) time
![Page 4: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/4.jpg)
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
R RGB RGB RGB RGB RGB RGB
R GB G RGB RGB GB RGB
R B G RB B B RGB
Forward Checking in Map Coloring
Empty set: the current assignment {(WA R), (Q G), (V B)}does not lead to a solution
4
![Page 5: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/5.jpg)
Forward Checking in Map Coloring
TWA
NT
SA
Q
NSW
V
Contradiction that forward checking did not detect
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
R RGB RGB RGB RGB RGB RGB
R GB G RGB RGB GB RGB
R B G RB B B RGB
5
![Page 6: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/6.jpg)
Forward Checking in Map Coloring
TWA
NT
SA
Q
NSW
V
Contradiction that forward checking did not detect
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
R RGB RGB RGB RGB RGB RGB
R GB G RGB RGB GB RGB
R B G RB B B RGB
Detecting this contradiction requires a more powerful constraint propagation technique
6
![Page 7: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/7.jpg)
Constraint Propagation for Binary Constraints
REMOVE-VALUES(X,Y)1. removed false2. For every value v in the domain of Y do
– If there is no value u in the domain of X such that the constraint on (X,Y) is satisfied thena. Remove v from Y‘s domainb. removed true
3. Return removed7
REMOVE-VALUES(X,Y) removes every value of Y that is incompatible with the values of X
![Page 8: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/8.jpg)
Constraint Propagation for Binary Constraints
AC3 1. Initialize queue Q with all variables (not yet
instantiated)
2. While Q doa. X Remove(Q)b. For every (not yet instantiated) variable Y related to
X by a (binary) constraint do– If REMOVE-VALUES(X,Y) then
i. If Y’s domain = then exitii. Insert(Y,Q)
8
![Page 9: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/9.jpg)
Edge LabelingWe consider an image of a scene composed of polyhedral objects such that each vertex is the endpoint of exactly three edges
R&N: Chap. 24, pages 881-884 9
![Page 10: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/10.jpg)
Edge LabelingAn “edge extractor” has accurately extracted all the visible edges in the image. The problem is to label each edge as convex (+), concave (-), or occluding () such that the complete labeling is physically possible
10
![Page 11: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/11.jpg)
Convex edges
Concave edgesOccludin
gedges
11
![Page 12: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/12.jpg)
+
- -
++
++
+
The arrow isoriented suchthat the object is on the right ofthe occluding edge
12
![Page 13: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/13.jpg)
One Possible Edge Labeling
+
++
+
+
+
+
+
++
--
13
![Page 14: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/14.jpg)
Junction Types
Fork
L
T
Y
14
![Page 15: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/15.jpg)
Junction Label Sets
+ + --
-- - + +
++ +
+
+
--
--
-+
(Waltz, 1975; Mackworth, 1977) 15
![Page 16: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/16.jpg)
Edge Labeling as a CSP
A variable is associated with each junction
The domain of a variable is the label set associated with the junction type
Constraints: The values assigned to two adjacent junctions must give the same label to the joining edge
16
![Page 17: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/17.jpg)
Q = (X1, X2, X3, ...)
X1
X5
X3
X8
X12
X2
X4
AC3 Applied to Edge Labeling
17
![Page 18: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/18.jpg)
+ -
+
-+- -
++
X1
X5
Q = (X1, ...)
AC3 Applied to Edge Labeling
18
![Page 19: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/19.jpg)
+ -
+
-+- -
++
X1
X5
Q = (X1, ...)
19
![Page 20: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/20.jpg)
+ -
+
-+- -
++
X5
Q = (X5, ...)
20
![Page 21: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/21.jpg)
+
+
+
+---
-- -
+
Q = (X5, ...)
X5
X3
21
![Page 22: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/22.jpg)
+
+
+
+---
-- -
+
Q = (X5, ...)
X5
X3
22
![Page 23: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/23.jpg)
+
+
+
+---
-- -
+
Q = (X3, ...)
X3
23
![Page 24: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/24.jpg)
+
+
+
+
+
-- - + +
++
Q = (X3, ...)
X3
X8
+
24
![Page 25: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/25.jpg)
+
+
+
+
+
-- - + +
++
Q = (X3, ...)
X3
X8
+
25
![Page 26: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/26.jpg)
+
+
+
+
+
-- - + +
++
Q = (X8, ...)
X8
+
26
![Page 27: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/27.jpg)
+
+
- -++
+ + --
+
X12
X8
Q = (X8, ...)
27
![Page 28: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/28.jpg)
Complexity Analysis of AC3
n = number of variables d = size of initial
domains s = maximum number of
constraints involving a given variable (s n-1)
Each variable is inserted in Q up to d times
REMOVE-VALUES takes O(d2) time
AC3 takes O(ndsd2) = O(nsd3) time
Usually more expensive than forward checking
REMOVE-VALUES(X,Y)1. removed f alse2. For every value v in the domain of Y do
– I f there is no value u in the domain of X such that the constraint on (x,y) is satisfied thena. Remove v f rom Y‘s domainb. removed true
3. Return removed
28
AC3 1. Initialize queue Q with all variables (not
yet instantiated)
2. While Q doa. X Remove(Q)b. For every (not yet instantiated) variable
Y related to X by a (binary) constraint do– If REMOVE-VALUES(X,Y) then
i. If Y’s domain = then exitii. Insert(Y,Q)
![Page 29: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/29.jpg)
Is AC3 all that we need? No !! AC3 can’t detect all contradictions among
binary constraints
X
Z
YXY
XZ YZ
{1, 2}
{1, 2}{1, 2}
29
![Page 30: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/30.jpg)
Is AC3 all that we need? No !! AC3 can’t detect all contradictions among
binary constraints
X
Z
YXY
XZ YZ
{1, 2}
{1, 2}{1, 2}
REMOVE-VALUES(X,Y)1. removed false2. For every value v in the domain of Y do
– If there is no value u in the domain of X such that the constraint on (X,Y) is satisfied thena. Remove v from Y‘s domainb. removed true
3. Return removed 30
![Page 31: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/31.jpg)
Is AC3 all that we need? No !! AC3 can’t detect all contradictions among
binary constraints
X
Z
YXY
XZ YZ
{1, 2}
{1, 2}{1, 2}
REMOVE-VALUES(X,Y)1. removed false2. For every value v in the domain of Y do
– If there is no value u in the domain of X such that the constraint on (X,Y) is satisfied thena. Remove v from Y‘s domainb. removed true
3. Return removed
REMOVE-VALUES(X,Y,Z)1. removed false2. For every value w in the domain of Z do
– If there is no pair (u,v) of values in the domains of X and Y verifying the constraint on (X,Y) such that the constraints on (X,Z) and (Y,Z) are satisfied thena. Remove w from Z‘s domainb. removed true
3. Return removed31
![Page 32: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/32.jpg)
Is AC3 all that we need? No !! AC3 can’t detect all contradictions among
binary constraints
Not all constraints are binary
X
Z
YXY
XZ YZ
{1, 2}
{1, 2}{1, 2}
32
![Page 33: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/33.jpg)
Tradeoff
Generalizing the constraint propagation algorithm increases its time complexity
Tradeoff between time spent in backtracking search and time spent in constraint propagation
A good tradeoff when all or most constraints are binary is often to combine backtracking with forward checking and/or AC3 (with REMOVE-VALUES for two variables)
33
![Page 34: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/34.jpg)
Modified Backtracking Algorithm with AC3
CSP-BACKTRACKING(A, var-domains)1. If assignment A is complete then return A2. Run AC3 and update var-domains accordingly3. If a variable has an empty domain then return
failure4. X select a variable not in A5. D select an ordering on the domain of X6. For each value v in D do
a. Add (Xv) to Ab. var-domains forward checking(var-domains, X, v, A)c. If no variable has an empty domain then
(i) result CSP-BACKTRACKING(A, var-domains)(ii) If result failure then return result
d. Remove (Xv) from A
7. Return failure34
![Page 35: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/35.jpg)
A Complete Example:4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
1) The modified backtracking algorithm starts by calling AC3, which removes no value
35
![Page 36: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/36.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
2) The backtracking algorithm then selects a variable and a value for this variable. No heuristic helps in this selection. X1 and the value 1 are arbitrarily selected
36
![Page 37: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/37.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
3) The algorithm performs forward checking, which eliminates 2 values in each other variable’s domain 37
![Page 38: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/38.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
4) The algorithm calls AC3
38
![Page 39: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/39.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
4) The algorithm calls AC3, which eliminates 3 from the domain of X2
X2 = 3 isincompatiblewith any of the remaining valuesof X3
REMOVE-VALUES(X,Y)1. removed f alse2. For every value v in the domain of Y do
– I f there is no value u in the domain of X such that the constraint on (x,y) is satisfied thena. Remove v f rom Y‘s domainb. removed true
3. Return removed
39
![Page 40: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/40.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
4) The algorithm calls AC3, which eliminates 3 from the domain of X2, and 2 from the domain of X3
40
![Page 41: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/41.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
4) The algorithm calls AC3, which eliminates 3 from the domain of X2, and 2 from the domain of X3, and 4 from the domain of X3
41
![Page 42: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/42.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
5) The domain of X3 is empty backtracking
42
![Page 43: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/43.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
6) The algorithm removes 1 from X1’s domain and assign 2 to X1 43
![Page 44: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/44.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
7) The algorithm performs forward checking
44
![Page 45: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/45.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
8) The algorithm calls AC3
45
![Page 46: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/46.jpg)
4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{1,2,3,4}X4
{1,2,3,4}
X2
{1,2,3,4}
8) The algorithm calls AC3, which reduces the domains of X3 and X4 to a single value
46
![Page 47: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/47.jpg)
Exploiting the Structure of CSP
If the constraint graph contains several components, then solve one independent CSP per component
TWA
NT
SA
Q
NSW
V
47
![Page 48: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/48.jpg)
Exploiting the Structure of CSP
If the constraint graph is a tree, then :1. Order the variables from the
root to the leaves (X1, X2, …, Xn)
2. For j = n, n-1, …, 2 callREMOVE-VALUES(Xj, Xi) where Xi is the parent of Xj
3. Assign any valid value to X1
4. For j = 2, …, n doAssign any value to Xj consistent with the
value assigned to its parent Xi
X
Y Z
U V
W
(X, Y, Z, U, V, W)
48
![Page 49: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/49.jpg)
Exploiting the Structure of CSP
Whenever a variable is assigned a value by the backtracking algorithm, propagate this value and remove the variable from the constraint graph
WA
NT
SA
Q
NSW
V
49
![Page 50: Constraint Propagation …](https://reader035.fdocuments.in/reader035/viewer/2022062410/56815853550346895dc5ac97/html5/thumbnails/50.jpg)
WA
NTQ
NSW
V
Exploiting the Structure of CSP
Whenever a variable is assigned a value by the backtracking algorithm, propagate this value and remove the variable from the constraint graph
If the graph becomes a tree, then proceed as shown in previousslide
50