constraint propagation
play

Constraint Propagation (Where a better exploitation of the is the - PDF document

Constraint Propagation Constraint Propagation (Where a better exploitation of the is the process of determining how the constraints further reduces the constraints and the possible values of one need to make decisions) variable affect


  1. Constraint Propagation … Constraint Propagation (Where a better exploitation of the … is the process of determining how the constraints further reduces the constraints and the possible values of one need to make decisions) variable affect the possible values of other variables R&N: Chap. 5 + Chap. 24, p. 881-884 It is an important form of “least-commitment” reasoning 1 2 Forward checking is only on simple Forward Checking in Map Coloring form of constraint propagation Empty set: the current assignment When a pair (X � v) is added to assignment A do: {(WA � R), (Q � G), (V � B)} For each variable Y not in A do: For every constraint C relating Y to variables in A do: does not lead to a solution Remove all values from Y’s domain that do not satisfy C WA NT Q NSW V SA T n = number of variables � RGB RGB RGB RGB RGB RGB RGB d = size of initial domains � R RGB RGB RGB RGB RGB RGB s = maximum number of constraints � involving a given variable (s ≤ n-1) R GB G RGB RGB GB RGB Forward checking takes O(nsd) time R B G RB B B RGB � 3 4 Forward Checking in Map Coloring Forward Checking in Map Coloring Contradiction that forward Contradiction that forward NT NT checking did not detect checking did not detect Q Q WA WA T T Detecting this contradiction requires a more NSW NSW SA SA p powerful constraint propagation technique f p p g q V V WA NT Q NSW V SA T WA NT Q NSW V SA T RGB RGB RGB RGB RGB RGB RGB RGB RGB RGB RGB RGB RGB RGB R RGB RGB RGB RGB RGB RGB R RGB RGB RGB RGB RGB RGB R GB G RGB RGB GB RGB R GB G RGB RGB GB RGB R B G RB B B RGB R B G RB B B RGB 5 6 1

  2. Constraint Propagation Constraint Propagation for Binary Constraints for Binary Constraints REMOVE-VALUES(X,Y) AC3 1. removed � false 1. Initialize queue Q with all variables (not yet instantiated) 2. For every value v in the domain of Y do 2. While Q ≠ ∅ do – If there is no value u in the domain of X such that a. X � Remove(Q) th the constraint on (X,Y) is satisfied then t i t (X Y) i ti fi d th b. For every (not yet instantiated) variable Y related to X a. Remove v from Y‘s domain by a (binary) constraint do b. removed � true – If REMOVE-VALUES(X,Y) then 3. Return removed i. If Y’s domain = ∅ then exit ii. Insert(Y,Q) 7 8 Edge Labeling Edge Labeling We consider an image of a scene composed of An “edge extractor” has accurately extracted polyhedral objects such that each vertex is all the visible edges in the image. The problem is the endpoint of exactly three edges to label each edge as convex (+), concave (-), or occluding ( � ) such that the complete labeling is physically possible R&N: Chap. 24, pages 881-884 9 10 The arrow is Concave + oriented such + edges that the object Occluding + is on the right of edges the occluding - - edge + + + Convex edges 11 12 2

  3. One Possible Edge Labeling Junction Types L Fork T + + + + + + + - - + Y + + + + 13 14 Junction Label Sets Edge Labeling as a CSP � A variable is associated with each - - + + junction � The domain of a variable is the label set m f - + + - - + + associated with the junction type - - - - + + + � Constraints: The values assigned to two adjacent junctions must give the same label to the joining edge - + (Waltz, 1975; Mackworth, 1977) 15 16 AC3 Applied to Edge Labeling AC3 Applied to Edge Labeling Q = (X 1 , X 2 , X 3 , ...) Q = (X 1 , ...) - + + - - + + X 5 X 5 X 3 3 X 1 X X X 1 X 2 X 12 X 4 X 8 - + 17 18 3

  4. Q = (X 1 , ...) Q = (X 5 , ...) - - + + + + - - - - + + + + X 5 X 5 X 1 X - - + + 19 20 Q = (X 5 , ...) Q = (X 5 , ...) + + X 5 X 5 + + X 3 X 3 3 3 - - - - - - - - + + + + - - - - + + 21 22 Q = (X 3 , ...) Q = (X 3 , ...) + + + + X 3 X 3 3 3 + X 8 - - - - + + + + - + + - - + + - - + + 23 24 4

  5. Q = (X 3 , ...) Q = (X 8 , ...) + + + + X 3 3 + + X 8 X 8 + + + + - - + + + + + + - - - - + + + + 25 26 Complexity Analysis of AC3 Q = (X 8 , ...) � n = number of variables AC3 1. Initialize queue Q with all variables (not yet - - � d = size of initial domains + + instantiated) 2. While Q ≠ ∅ do � s = maximum number of a. X � Remove(Q) constraints involving a + + b. For every (not yet instantiated) variable Y related to X by a (binary) constraint do given variable (s ≤ n-1) given variable (s ≤ n 1) – If REMOVE VALUES(X Y) then If REMOVE-VALUES(X,Y) then � Each variables is inserted i. If Y’s domain = ∅ then exit + X 12 ii. Insert(Y,Q) in Q up to d times REMOVE-VALUES takes O(d 2 ) X 8 � REMOVE-VALUES(X,Y) time 1. removed � false 2. For every value v in the domain of Y do � AC3 takes O(n × d × s × d 2 ) = – If there is no value u in the domain of X such that + + the constraint on (x,y) is satisfied then O(n × s × d 3 ) time - - a. Remove v from Y‘s domain b. removed � true � Usually more expensive 3. Return removed than forward checking 27 28 Is AC3 all that we need? Is AC3 all that we need? � No !! � No !! � AC3 can’t detect all contradictions among � AC3 can’t detect all contradictions among binary constraints binary constraints X ≠ Y X ≠ Y {1, 2} {1, 2} {1, 2} {1, 2} X Y X Y X ≠ Z Y ≠ Z REMOVE-VALUES(X,Y) X ≠ Z Y ≠ Z 1. removed � false 2. For every value v in the domain of Y do {1, 2} {1, 2} Z Z – If there is no value u in the domain of X such that the constraint on (X,Y) is satisfied then a. Remove v from Y‘s domain b. removed � true 3. Return removed 29 30 5

  6. Is AC3 all that we need? Is AC3 all that we need? � No !! � No !! � AC3 can’t detect all contradictions among � AC3 can’t detect all contradictions among binary constraints binary constraints X ≠ Y X ≠ Y {1, 2} {1, 2} {1, 2} {1, 2} X Y X Y REMOVE-VALUES(X,Y,Z) 1. removed � false REMOVE-VALUES(X,Y) X ≠ Z Y ≠ Z X ≠ Z Y ≠ Z 2. For every value w in the domain of Z do 1. removed � false – If there is no pair (u,v) of values in the domains 2. For every value v in the domain of Y do {1, 2} {1, 2} Z Z of X and Y verifying the constraint on (X,Y) such – If there is no value u in the domain of X such that the constraints on (X,Z) and (Y,Z) are that the constraint on (X,Y) is satisfied then satisfied then � Not all constraints are binary a. Remove v from Y‘s domain a. Remove w from Z‘s domain b. removed � true b. removed � true 3. Return removed 31 32 3. Return removed Modified Backtracking Tradeoff Algorithm with AC3 Generalizing the constraint propagation algorithm CSP-BACKTRACKING(A, var-domains) increases its time complexity 1. If assignment A is complete then return A 2. Run AC3 and update var-domains accordingly � Tradeoff between time spent in 3. If a variable has an empty domain then return failure backtracking search and time spent in backtracking search and time spent in 4. 4 X � select a variable not in A X � select a variable not in A constraint propagation 5. D � select an ordering on the domain of X 6. For each value v in D do A good tradeoff when all or most constraints are a. Add (X � v) to A binary is often to combine backtracking with b. var-domains � forward checking(var-domains, X, v, A) forward checking and/or AC3 (with REMOVE- c. If no variable has an empty domain then VALUES for two variables) (i) result � CSP-BACKTRACKING(A, var-domains) (ii) If result ≠ failure then return result d. Remove (X � v) from A 7. Return failure 33 34 A Complete Example: 4-Queens Problem 4-Queens Problem X 1 X 2 X 1 X 2 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 1 2 3 4 1 2 3 4 1 1 2 2 3 3 4 4 X 3 X 4 X 3 X 4 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 1) The modified backtracking algorithm starts by 2) The backtracking algorithm then selects a variable calling AC3, which removes no value and a value for this variable. No heuristic helps in this selection. X 1 and the value 1 are arbitrarily selected 35 36 6

  7. 4-Queens Problem 4-Queens Problem X 1 X 2 X 1 X 2 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 1 2 3 4 1 2 3 4 1 1 2 2 3 3 4 4 X 3 X 4 X 3 X 4 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 3) The algorithm performs forward checking, which 4) The algorithm calls AC3 eliminates 2 values in each other variable’s domain 37 38 4-Queens Problem 4-Queens Problem REMOVE-VALUES(X,Y) 1. removed � false 2. 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 then a. Remove v from Y‘s domain X 1 X 2 X 1 X 2 b. removed � true 3. Return removed {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 1 2 3 4 1 2 3 4 1 X 2 = 3 is 1 inc mp tibl incompatible 2 with any of the 2 remaining values 3 3 of X 3 4 4 X 3 X 4 X 3 X 4 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 4) The algorithm calls AC3, which eliminates 3 from the 4) The algorithm calls AC3, which eliminates 3 from the domain of X 2 domain of X 2 , and 2 from the domain of X 3 39 40 4-Queens Problem 4-Queens Problem X 1 X 2 X 1 X 2 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 1 2 3 4 1 2 3 4 1 1 2 2 3 3 4 4 X 3 X 4 X 3 X 4 {1,2,3,4} {1,2,3,4} {1,2,3,4} {1,2,3,4} 4) The algorithm calls AC3, which eliminates 3 from the 5) The domain of X 3 is empty � backtracking domain of X 2 , and 2 from the domain of X 3 , and 4 from the domain of X 3 41 42 7

Recommend


More recommend