Basic Consistency Methods Foundations of Constraint Processing CSCE421/821, Spring 2011 www.cse.unl.edu/~cse421 All questions: cse421@cse.unl.edu Berthe Y. Choueiry (Shu-we-ri) Avery Hall, Room 360 choueiry@cse.unl.edu Tel: +1(402)472-5444 Foundations of Constraint Processing Basic Consistency Methods 1 Lecture Sources Required reading 1. Algorithms for Constraint Satisfaction Problems, Mackworth and Freuder AIJ'85 2. Sections 3.1, 3.2, 3.3. Chapter 3. Constraint Processing. Dechter Recommended 1. Sections 3.4—3.10. Chapter 3. Constraint Processing. Dechter 2. Networks of Constraints: Fundamental Properties and Application to Picture Processing, Montanari, Information Sciences 74 3. Consistency in Networks of Relations, Mackworth AIJ'77 4. Constraint Propagation with Interval Labels, Davis, AIJ'87 5. Path Consistency on Triangulated Constraint Graphs, Bliek & SamHaroud IJCAI'99 Foundations of Constraint Processing Basic Consistency Methods 2 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison and CSP parameters. 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 3 Consistency checking Motivation • CSP are solved with search (conditioning) • Search performance is affected by: - problem size - amount of backtracking • Backtracking may yield.. thrashing Thrashing Exploring non-promising sub-trees and rediscovering the same inconsistencies over and over again Malady of backtrack search Foundations of Constraint Processing Basic Consistency Methods 4 (Some) causes of thrashing Search order: V1, V2, V3, V4, V5 V1 {1, 2, 3} {1, 2, 3} V3<V1 V3 { 0, 1, 2} V3<V4 V2 V3<V2 V3>0 V3<V5 V4 V5 {1, 2} V5<V4 { 1, 2} What happens in search if we: • do not check CV3 (node inconsistency) • do not check constraint CV3,V5 (arc inconsistency) • do not check constraints CV3,V4, CV3,V5, and CV4,V5 (path inconsistency) Foundations of Constraint Processing Basic Consistency Methods 5 Consistency checking Goal: eliminate inconsistent combinations Algorithms (for binary constraints): • • • • Node consistency Arc consistency (AC-1, AC-2, AC-3, ..., AC-7, AC-3.1, etc.) Path consistency (PC-1, PC-2, DPC, PPC, etc.) Constraints of arbitrary arity: – Waltz algorithm ancestor of AC's – Generalized arc-consistency (Dechter, Section 3.5.1 ) – Relational m-consistency (Dechter, Section 8.1) Foundations of Constraint Processing Basic Consistency Methods 6 Overview of Recommended Reading • Davis, AIJ'77 – Focuses on the Waltz algorithm – Studies its performance and quiescence for given: • Constraint types (bounded diff, algebraic, etc.) • Domains types (continuous or finite) • Mackworth, AIJ'77 – presents NC, AC-1, AC-2, PC-1, PC-2 • Mackworth and Freuder, AIJ'85 – studies their complexity Mackworth and Freuder concentrate on finite domains More people work on finite domains than on continuous ones Continuous domains can be quite tough Foundations of Constraint Processing Basic Consistency Methods 7 Constraint Propagation with Interval Labels Ernest Davis • `Old' paper (1987): terminology slightly different • Interval labels: continuous domains – Section 8: sign labels (discrete) • Concerned with Waltz algorithm (e.g., quiescence, completeness) • Constraint types vs. domain types (Table 3) • Addresses applications of reasoning about – Physical Systems (circuit, SPAM) – time relations (TMM) • Advice: read Section 3, more if you wish Foundations of Constraint Processing Basic Consistency Methods 8 Waltz algorithm for label inference Vi • REFINE(C(Vi, Vk, Vm, Vn), Vi) finds a new label for Vi consistent with C. C Vk Vm Vn • REVISE(C (Vi, Vk, Vm, Vn)) refines the domains of Vi, Vk, Vm, Vn by iterating over these variables until quiescence (i.e., no domains is further refined) • Waltz Algorithm – revises all constraints by iterating over each constraint connected to a variable whose domain has been revised – Is the ancestor of arc-consistency Foundations of Constraint Processing Basic Consistency Methods 9 WARNING → Completeness: (i.e., for solving the CSP) Running the Waltz Algorithm does notB solve the problem. A {1, 2, 3 } A {2, 3 } {2, 3, 4 } B {2, 3 } A=2 B=3 is still not a solution! → Quiescence: The Waltz algorithm may go into infinite loops even if problem is solvable x [0, 100] x=y y [0, 100] x = 2y → Davis characterizes the completeness and quiescence of the Waltz algorithm (see Table 3) in terms of – constraint types – domain types Foundations of Constraint Processing Basic Consistency Methods 10 Importance of this paper Establishes that constraints of bounded differences (temporal reasoning) can be efficiently solved by the Waltz algorithm (O(n3), n number of variables) Early paper that attracts attention on the difficulty of label propagation in interval labels (continuous domains). This work has been continued by Faltings (AIJ 92) who studied the early-quiescence problem of the Waltz algorithm. Foundations of Constraint Processing Basic Consistency Methods 11 Basic consistency algorithms Examining finite, binary CSPs and their complexity Notation: Given variables i, j, k with values x, y, z, the predicate Pijk(x, y, z) is true iff the 3-tuple x, y, z Cijk Node consistency: Arc consistency: Path consistency: checking Pi(x) checking Pij(x,y) bit-matrix manipulation Foundations of Constraint Processing Basic Consistency Methods 12 Worst-case asymptotic complexity Worst-case complexity time space as a function of the input parameters Upper bound: f(n) is O(g(n)) means that f(n) c.g(n) f grows as g or slower Lower bound: f(n) is (h(n)) means that f(n) c.h(n) f grows as g or faster Input parameters for a CSP: n = number of variables a = (max) size of a domain dk = degree of Vk ( n-1) e = number of edges (or constraints) [(n-1), n(n-1)/2] Foundations of Constraint Processing Basic Consistency Methods 13 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison and CSP parameters. 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 14 Node consistency (NC) Procedure NC(i): Di Di { x | Pi(x) } Begin for i 1 until n do NC(i) end Foundations of Constraint Processing Basic Consistency Methods 15 Complexity of NC Procedure of NC(i) Di Di { x | Pi(x) } Begin for i 1 until n do NC(i) end • For each variable, we check a values • We have n variables, we do n.a checks • NC is O(a.n) Foundations of Constraint Processing Basic Consistency Methods 16 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison and CSP parameters. 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 17 Arc-consistency Adapted from Dechter Definition: Given a constraint graph G, • A variable Vi is arc-consistent relative to Vj iff for every value aDVi, there exists a value bDVj | (a, b)CVi,Vj. Vi Vj 1 1 2 Vj 1 2 2 3 Vi 3 2 3 • The constraint CVi,Vj is arc-consistent iff – Vi is arc-consistent relative to Vj and – Vj is arc-consistent relative to Vi. • A binary CSP is arc-consistent iff every constraint (or sub-graph of size 2) is arc-consistent Foundations of Constraint Processing Basic Consistency Methods 18 Procedure Revise Revises the domains of a variable i Procedure Revise(i,j): Begin DELETE false for each x Di do if there is no y Dj such that Pij(x, y) then begin delete x from Di DELETE true end return DELETE end • Revise is directional • What is the complexity of Revise? {a2} Foundations of Constraint Processing Basic Consistency Methods 19 Revise: example R. Dechter Apply the Revise procedure to the following example X Y X+Y = 10 { 1, 2, .., 10} {5, 6, .. 15} Foundations of Constraint Processing Basic Consistency Methods 20 Effect of Revise Question: Adapted from Dechter Vj Vi 1 1 Vi Vj 1 Given 2 2 2 2 • two variables Vi and Vj 3 3 3 • their domains DVi and DVj, and • the constraint CVi,Vj, write the effect of the Revise procedure as a sequence of operations in relational algebra Hint: • Think about the domain DVi as a unary constraint CVi and • consider the composition of this unary constraint and the binary one.. Solution: DVi DVi Vi (CVi,Vj DVi) This is actually equivalent to DVi Vi (CVi,Vj DVi) Foundations of Constraint Processing Basic Consistency Methods 21 Arc Consistency (AC-1) Procedure AC-1: 1 begin 2 for i 1 until n do NC(i) 3 Q {(i, j) | (i,j) arcs(G), i j } 4 repeat 5 begin 6 CHANGE false 7 for each (i, j) Q do CHANGE ( REVISE(i, j) or CHANGE ) 8 end 9 until ¬ CHANGE 10 end • AC-1 does not update Q, the queue of arcs • No algorithm can have time complexity below O(ea2) • Alert: Algorithms do not, but should, test for empty domains Foundations of Constraint Processing Basic Consistency Methods 22 Warning • What I don’t like about the algorithms as specified in most papers is that they do not check for domain wipe-out. • In your code, always check for domain wipe out and terminate/interrupt the algorithm when that occurs • In practice may save lots of #CC and cycles Foundations of Constraint Processing Basic Consistency Methods 23 Arc consistency 1. AC may discover the solution Example borrowed from Dechter V1 V1 V3 V2 V1 V2 V3 V2 V2 V3 V2 V1 V3 V1 V1 V2 V3 V1 V3 V2 V3 Foundations of Constraint Processing Basic Consistency Methods 24 Arc consistency 2. AC may discover inconsistency Example borrowed from Dechter X {1, 2, 3 } Z< X X< Y Y { 1 , 2 , 3 }Z {1, 2, 3 } Y< Z Foundations of Constraint Processing Basic Consistency Methods 25 NC & AC Example courtesy of M. Fromherz AC propagates bound x [0, 10] x x y-3 y [0, 10] Unary constraint x>3 is imposed AC propagates bounds again [0, 7] x x y-3 x y-3 y [3, 10] [4, 7] y [7, 10] Foundations of Constraint Processing Basic Consistency Methods 26 Complexity of AC-1 Procedure AC-1: 1 begin 2 for i 1 until n do NC(i) 3 Q {(i, j) | (i,j) arcs(G), i j 4 repeat 5 begin 6 CHANGE false 7 for each (i, j) Q do CHANGE (REVISE(i, j) or CHANGE) 8 end 9 until ¬ CHANGE 10 end Note: Q is not modified and |Q| = 2e • 4 9 repeats at most n·a times • Each iteration has |Q| = 2e calls to REVISE • Revise requires at most a2 checks of Pij AC-1 is O(a3 · n · e) Foundations of Constraint Processing Basic Consistency Methods 27 AC versions • AC-1 does not update Q, the queue of arcs • AC-2 iterates over arcs connected to at least one node whose domain has been modified. Nodes are ordered. • AC-3 same as AC-2, nodes are not ordered Foundations of Constraint Processing Basic Consistency Methods 28 Arc consistency (AC-3) AC-3 iterates over arcs connected to at least one node whose domain has been modified Procedure AC-3: 1 begin 2 for i 1 until n do NC(i) 3 Q { (i, j) | (i, j) arcs(G), i j } 4 While Q is not empty do 5 begin 6 select and delete any arc (k, m) from Q 7 If Revise(k, m) then Q Q { (i, k) | (i, k) arcs(G), i k, i m } 8 end 9 end Foundations of Constraint Processing Basic Consistency Methods 29 Complexity of AC-3 Procedure AC-3: 1 begin 2 for i 1 until n do NC(i) 3 Q {(i, j) | (i, j) arcs(G), i j } 4 While Q is not empty do 5 begin 6 select and delete any arc (k, m) from Q 7 If Revise(k, m) then Q Q { (i, k) | (i, k) arcs(G), i k, i m } 8 end 9 end • • First |Q| = 2e, then it grows and shrinks 48 Worst case: – 1 element is deleted from DVk per iteration – none of the arcs added is in Q • Line 7: a·(dk - 1) n • Lines 4 - 8: 2e k 1 a d k 1 2e a (2e n) • Revise: a2 checks of Pij AC-3 is O(a2(2e + a(2e-n))) Connected graph (e n – 1), AC-3 is O(a3e) If AC-p, AC-3 is O(a2e) AC-3 is (a2e) Complete graph: O(a3n2) Foundations of Constraint Processing Basic Consistency Methods 30 Example: Apply AC-3 Example: Apply AC-3 Thanks to Xu Lin V2 V1 { 1, 2, 3, 4, 5 } { 1, 2, 3, 4, 5 } V3 { 1, 2, 3, 4, 5 } { 1, 2, 3, 4, 5 } V2 V1 V4 V3 { 1, 3, 5 } { 1, 2, 3, 4 } { 1, 3, 5 } { 1, 2, 3, 5 } V4 DV1 = {1, 2, 3, 4, 5} DV2 = {1, 2, 3, 4, 5} DV3 = {1, 2, 3, 4, 5} DV4 = {1, 2, 3, 4, 5} CV2,V3 = {(2, 2), (4, 5), (2, 5), (3, 5), (2, 3), (5, 1), (1, 2), (5, 3), (2, 1), (1, 1)} CV1,V3 = {(5, 5), (2, 4), (3, 5), (3, 3), (5, 3), (4, 4), (5, 4), (3, 4), (1, 1), (3, 1)} CV2,V4 = {(1, 2), (3, 2), (3, 1), (4, 5), (2, 3), (4, 1), (1, 1), (4, 3), (2, 2), (1, 5)} Foundations of Constraint Processing Basic Consistency Methods 31 Applying AC-3 Thanks to Xu Lin • Queue = {CV2, V4, CV4,V2, CV1,V3, CV2,V3, CV3, V1, CV3,V2} • Revise(V2,V4): DV2 DV2 \ {5} = {1, 2, 3, 4} • Queue = {CV4,V2, CV1,V3, CV2,V3, CV3, V1, CV3, V2} • Revise(V4, V2): DV4 DV4 \ {4} = {1, 2, 3, 5} • Queue = {CV1,V3, CV2,V3, CV3, V1, CV3, V2} • Revise(V1, V3): DV1 {1, 2, 3, 4, 5} • Queue = {CV2,V3, CV3, V1, CV3, V2} • Revise(V2, V3): DV2 {1, 2, 3, 4} Foundations of Constraint Processing Basic Consistency Methods 32 Applying AC-3 (cont.) Thanks to Xu Lin • Queue = {CV3, V1, CV3, V2} • Revise(V3, V1): DV3 DV3 \ {2} = {1, 3, 4, 5} • Queue = {CV2, V3, CV3, V2} • Revise(V2, V3): DV2 DV2 • Queue = {CV3, V2} • Revise(V3, V2): DV3 {1, 3, 5} • Queue = {CV1, V3} • Revise(V1, V3): DV1 {1, 3, 5} END Foundations of Constraint Processing Basic Consistency Methods 33 Main Improvements Mohr & Henderson (AIJ 86): • AC-3 O(a3e) AC-4 O(a2e) • AC-4 is optimal • Trade repetition of consistency-check operations with heavy bookkeeping on which and how many values support a given value for a given variable • Data structures it uses: – – – • m: values that are active, not filtered s: lists all vvp's that support a given vvp counter: given a vvp, provides the number of support provided by a given variable How it proceeds: 1. Generates data structures 2. Prepares data structures 3. Iterates over constraints while updating support in data structures Foundations of Constraint Processing Basic Consistency Methods 34 Step 1: Generate 3 data structures • m and s have as many rows as there are vvp’s in the problem • counter has as many rows as there are tuples in the constraints m (V4 , 5) (V3 , 2) (V3 , 3) (V2 , 2) (V4 , 4) s T T T T T (V4 , 5) (V3 , 2) (V3 , 3) (V2 , 2) (V4 , 4) counter NIL NIL NIL NIL NIL (V4 , V2 ), 3 0 (V4 , V2 ), 2 0 (V4 , V2 ), 1 0 (V2 , V3 ), 1 0 (V1, V3 ), 4 0 Foundations of Constraint Processing Basic Consistency Methods 35 Step 2: Prepare data structures Data structures: s and counter. • • Checks for every constraint CVi,Vj all tuples Vi=ai, Vj=bj_) When the tuple is allowed, then update: – s(Vj,bj) s(Vj,bj) {(Vi, ai)} and – counter(Vj,bj) (Vj,bj) + 1 Update counter ((V2, V3), 2) to value 1 Update counter ((V3, V2), 2) to value 1 Update s-htable (V2, 2) to value ((V3, 2)) Update s-htable (V3, 2) to value ((V2, 2)) Update counter ((V2, V3), 4) to value 1 Update counter ((V3, V2), 5) to value 1 Update s-htable (V2, 4) to value ((V3, 5)) Update s-htable (V3, 5) to value ((V2, 4)) Foundations of Constraint Processing Basic Consistency Methods 36 Constraints CV2,V3 and CV3,V2 S (V4, 5) Counter Nil (V3, 2) ((V2, 1), (V2, 2)) (V3, 3) ((V2, 5), (V2, 2)) (V4, V2), 3 0 (V4, V2), 2 0 (V4, V2), 1 0 (V2, 2) ((V3,1), (V3,3), (V3, 5), (V3,2)) (V2, V3), 1 2 (V3, 1) ((V2, 1), (V2, 2), (V2, 5)) (V2, V3), 3 4 (V2, 3) ((V3, 5)) (V4, V2), 5 1 (V1, 2) Nil (V2, V4), 1 0 (V2, 1) ((V3, 1), (V3, 2)) (V2, V3), 4 0 (V1, 3) Nil (V4, V2), 4 1 (V3, 4) Nil (V2, V4), 2 0 (V4, 2) Nil (V2, V3), 5 0 (V3, 5) ((V2, 3), (V2, 2), (V2, 4)) (V2, V4), 3 2 (v4, 3) Nil (V2, V4), 4 0 (V1, 1) Nil (V2, V4), 5 0 (V2, 4) ((V3, 5)) (V3, V1), 1 0 (V2, 5) ((V3, 3), (V3, 1)) (V3, V1), 2 0 (V4, 1) Nil (V3, V1), 3 0 (V1, 4) Nil … … (V1, 5) Nil (V3, V2), 4 0 (V4, 4) Nil Etc… Etc . Updating m Note that (V3, V2),4 0 thus we remove 4 from the domain of V3 and update (V3, 4) nil in m Updating counter Since 4 is removed from DV3 then for every (Vk, l) | (V3, 4) s[(Vk, l)], we decrement counter[(Vk, V3), l] by 1 Foundations of Constraint Processing Basic Consistency Methods 37 Summary of arc-consistency algorithms • AC-4 is optimal (worst-case) • Warning: worst-case complexity is pessimistic. Better worst-case complexity: AC-4 Better average behavior: AC-3 [Mohr & Henderson, AIJ 86] [Wallace, IJCAI 93] • AC-5: special constraints [Van Hentenryck, Deville, Teng 92] functional, anti-functional, and monotonic constraints • AC-6, AC-7: general but rely heavily on data structures for bookkeeping [Bessière & Régin] • Now, back to AC-3: AC-2000, AC-2001≡AC-3.1, AC3.3, etc. • Non-binary constraints: – GAC (general) – all-different (dedicated) [Mohr & Masini 1988] [Régin, 94] Foundations of Constraint Processing Basic Consistency Methods 38 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison & CSP parameters 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 39 CSP parameters ‹n, a, t, d› • n is number of variables • a is maximum domain size forbidden tuples • t is constraint tightness: t all tuples • d is constraint density d (e emin ) (emax emin ) where e is the #constraints, emin=(n-1), and Lately, we use constraint ratio p = e/emax emax = n(n-1)/2 → Constraints in random problems often generated uniform → Use only connected graphs (throw the unconnected ones away) Foundations of Constraint Processing Basic Consistency Methods 40 Criteria for performance comparison 1. Bounding time and space complexity (theoretical) – worst-case: always – average-case: never – best- case: sometimes 2. Counting #CC and #NV (theoretical, empirical) 3. Measuring CPU time (empirical) Foundations of Constraint Processing Basic Consistency Methods 41 Performance comparison Courtesy of Lin XU AC-3, AC-7, AC-4 on n=10,a=10,t,d=0.6 displaying #CC and CPU time AC-3 AC-4 AC-7 Foundations of Constraint Processing Basic Consistency Methods 42 Wisdom (?) Free adaptation from Bessière • When a single constraint check is very expensive to make, use AC-7. • When there is a lot of propagation, use AC-4 • When little propagation and constraint checks are cheap, use AC-3x Foundations of Constraint Processing Basic Consistency Methods 43 AC2001 • When checking (Vi,a) against Vj – Keep track of the Vj value that supports (Vi,a) –Last((Vi,a),Vi) • Next time when checking again (Vi,a) against Vj, we start from Last((Vi,a),Vi) and don’t have to traverse again the domain of Vj again or list of tuples in CViVj • Big savings.. Foundations of Constraint Processing Basic Consistency Methods 44 Performance comparison Courtesy of Shant AC3, AC3.1, AC4 on on n=40,a=16,t,d=0.15 displaying #CC and CPU time Foundations of Constraint Processing Basic Consistency Methods 45 AC-what? Instructor’s personal opinion • Used to recommend using AC-3.. • Now, recommend using AC2001 • Do the project on AC-* if you are curious.. [Régin 03] Foundations of Constraint Processing Basic Consistency Methods 46 AC is not enough Example borrowed from Dechter V1 V1 a b b = = V2 a a V3 b a b V2 a b V3 b a = Arc-consistent? Satisfiable? seek higher levels of consistency Foundations of Constraint Processing Basic Consistency Methods 47 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison and CSP parameters. 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 48 Consistency of a path A path (V0, V1, V2, …, Vm) of length m is consistent iff • • for any value xDV0 and for any value yDVm that are consistent (i.e., PV0 Vm(x, y)) a sequence of values z1, z2, … , zm-1 in the domains of variables V1, V2, …, Vm-1, such that all constraints between them (along the path, not across it) are satisfied (i.e., PV0 V1(x, z1) PV1 V2(z1, z2) … PVm-1 Vm(zm-1, zm) ) V2 V1 V0 for all x DV0 Vm-1 for all y DVm Vm Foundations of Constraint Processing Basic Consistency Methods 49 Note The same variable can appear more than once in the path Every time, it may have a different value Constraints considered: PV0,Vm and those along the path All other constraints are neglected V2 V1 V0 for all x DV0 Vm-1 for all y DVm Vm Foundations of Constraint Processing Basic Consistency Methods 50 Example: consistency of a path Check path length = 2, 3, 4, 5, 6, .... All mutex constraints V2 V1 {a, b, c} V3 {a, b, c} {a, b, c} {a, b, c} {a, b, c} V7 {a, b, c} {a, b, c} V4 V5 V6 Foundations of Constraint Processing Basic Consistency Methods 51 Path consistency: definition A path of length m is path consistent A CSP is path consistent Property of a CSP Definition: A CSP is path consistent (PC) iff every path is consistent (i.e., any length of path) Question: should we enumerate every path of any length? Answer: No, only length 2, thanks to [Mackworth AIJ'77] Foundations of Constraint Processing Basic Consistency Methods 52 Tools for PC-1 Two operators 1. Constraint composition: ( • ) R13 = R12 • R23 2. Constraint intersection: ( ) R13 R13, old R13, induced Foundations of Constraint Processing Basic Consistency Methods 53 Path consistency (PC-1) Achieved by composition and intersection (of binary relations expressed as matrices) over all paths of length two. Procedure PC-1: 1 Begin 2 Yn R 3 repeat 4 begin 5 Y0 Yn 6 For k 1 until n do 7 For i 1 until n do 8 For j 1 until n do 9 Ylij Yl-1ij Yl-1ik • Yl-1kk • Yl-1kj 10 end 11 until Yn = Y0 12 Y Yn 10 end Foundations of Constraint Processing Basic Consistency Methods 54 Properties of PC-1 Discrete CSPs [Montanari'74] 1. PC-1 terminates 2. PC-1 results in a path consistent CSP • PC-1 terminates. It is complete, sound (for finding PC network) • PC-2: Improves PC-1 similar to how AC3 improves AC-1 Complexity of PC-1.. Foundations of Constraint Processing Basic Consistency Methods 55 Complexity of PC-1 Procedure PC-1: 1 2 3 4 5 6 7 8 9 10 11 12 10 Begin Yn R repeat begin Y0 Yn For k 1 until n do For i 1 until n do For j 1 until n do Ylij Yl-1ij Yl-1ik • Yl-1kk • Yl-1kj end until Yn = Y0 Y Yn end Line 9: a3 Lines 6–10: n3. a3 Line 3: at most n2 relations x a2 elements PC-1 is O(a5n5) PC-2 is O(a5n3) and (a3n3) PC-1, PC-2 are specified using constraint composition Foundations of Constraint Processing Basic Consistency Methods 56 Enforcing Path Consistency (PC) General case: Complete graph Theorem: In a complete graph, if every path of length 2 is consistent, the network is path consistent [Mackworth AIJ'77] PC-1: two operations, composition and intersection Proof by induction. General case: Triangulated graph Theorem: In a triangulated graph, if every path of length 2 is consistent, the network is path consistent [Bliek & Sam-Haroud ‘99] PPC (partially path consistent) PC Foundations of Constraint Processing Basic Consistency Methods 57 Arbitrary Constraints PPC versus PC Algorithm Graph PC-p? Filtering PC-2 Complete PC-p Tight, not necessarily minimal PPC Triangulated PC-p Weaker filtering than PC-2 Foundations of Constraint Processing Basic Consistency Methods 58 Some improvements • Mohr & Henderson (AIJ 86) – PC-2 O(a5n3) PC-3 O(a3n3) – Open question: PC-3 optimal? • Han & Lee (AIJ 88) – PC-3 is incorrect – PC-4 O(a3n3) space and time • Singh (ICTAI 95) – PC-5 uses ideas of AC-6 (support bookkeeping) • Also: – PC8: iterates over domains, not constraints – PC2001: an improvement over PC8, not tested [Chmeiss & Jégou 1998] Project! [Bessière et al. 2005] Note: PC is seldom used in practical applications unless in presence of special type of constraints (e.g., bounded difference) Foundations of Constraint Processing Basic Consistency Methods 59 Path consistency as inference of binary constraints B B A< B A< B A A B<C B<C C A< C C Path consistency corresponds to inferring a new constraint (alternatively, tightening an existing constraint) between every two variables given the constraints that link them to a third variable Considers all subgraphs of 3 variables 3-consistency Foundations of Constraint Processing Basic Consistency Methods 60 Path consistency as inference of binary constraints Another example: V1 V1 a b a b V2 V3 a b a b V2 = a b V3 aa bb = a b a b V4 V4 Foundations of Constraint Processing Basic Consistency Methods 61 Question Adapted from Dechter Given three variables Vi, Vk, and Vj and the constraints CVi,Vk, CVi,Vj, and CVk,Vj, write the effect of PC as a sequence of operations in relational algebra. B B B A< B A< B A< B A A A B<C B<C B<C A< C A+ 3 > C C C A+3> C Solution: CVi,Vj CVi,Vj ij(CVi,Vk C -3 < A –C < 0 CVk,Vj) Foundations of Constraint Processing Basic Consistency Methods 62 Constraint propagation After Arc-consistency: 1 1 2 2 3 3 courtesy of Dechter 1 2 2 3 After Path-consistency: ( 0, 1 ) ( 0, 1 ) • ( 0, 1 ) ( 0, 1 ) ( 0, 1 ) ( 0, 1 ) Are these CSPs the same? – Which one is more explicit? – Are they equivalent? • The more propagation, – the more explicit the constraints – the more search is directed towards a solution Foundations of Constraint Processing Basic Consistency Methods 63 PC can detect unsatisfiability V1 a b V2 V3 a b aa bb Arc-consistent? a b V4 Path-consistent? Foundations of Constraint Processing Basic Consistency Methods 64 Warning: Does 3-consistency guarantee 2-consistency? B {red, {red,blue} blue} A C { red } { red } • Question: – Is this CSP 3-consistent? – is it 2-consistent? • Lesson: – 3-consistency does not guarantee 2-consistency Foundations of Constraint Processing Basic Consistency Methods 65 PC is not enough All mutex constraints V2 {a, b, c} {a, b, c} V7 {a, b, c} V1 V3 {a, b, c} V4 {a, b, c} {a, b, c} V5 Arc-consistent? {a, b, c} Path-consistent? V6 Satisfiable? we should seek (even) higher levels of consistency k-consistency, k = 1, 2, 3, …. …following lecture Foundations of Constraint Processing Basic Consistency Methods 66 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison and CSP parameters. 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 67 Minimality PC tightens the binary constraints The tightest possible binary constraints yield the minimal network Minimal network a.k.a. central problem Given two values for two variables, if they are consistent, then they appear in at least one solution. Note: • Minimal path consistent • The definition of minimal CSP is concerned with binary CSPs Foundations of Constraint Processing Basic Consistency Methods 68 Minimal CSP Minimal network a.k.a. central problem Given two values for two variables, if they are consistent, then they appear in at least one solution. Informally • In a minimal CSP the remainder of the CSP does not add any further constraint to the direct constraint CVi, Vj between the two variables Vi and Vj [Mackworth AIJ'77] • A minimal CSP is perfectly explicit: as far as the pair Vi and Vj is concerned, the rest of the network does not add any further constraints to the direct constraint CVi, Vj [Montanari'74] • The binary constraints are explicit as possible. [Montanari'74] Foundations of Constraint Processing Basic Consistency Methods 69 Decomposability • Any combination of values for k variables that satisfy the constraints between them can be extended to a solution. • Decomposability generalizes minimality Minimality: any consistent combination of values for any 2 variables is extendable to a solution Decomposability: any consistent combination of values for any k variables is extendable to a solution Decomposable Minimal Path Consistent Strong n-consistent n-consistent Solvable Foundations of Constraint Processing Basic Consistency Methods 70 Relations to (theory of) DB CSP Database Minimal • |C|-wise consistent • The relations join completely Decomposable ? Foundations of Constraint Processing Basic Consistency Methods 71 Outline 1. 2. 3. 4. Motivation and background Node consistency and its complexity Arc consistency and its complexity Criteria for performance comparison and CSP parameters. 5. Path consistency and its complexity 6. Global consistency properties – Minimality – Decomposability 7. When PC guarantees global consistency Foundations of Constraint Processing Basic Consistency Methods 72 PC approximates.. In general: • Decomposability minimality path consistent • PC is used to approximate minimality (which is the central problem) When is the approximation the real thing? Special cases: • When composition distributes over intersection, [Montanari'74] PC-1 on the completed graph guarantees minimality and decomposability • When constraints are convex [Bliek & Sam-Haroud 99] PPC on the triangulated graph guarantees minimality and decomposability (and the existing edges are as tight as possible) Foundations of Constraint Processing Basic Consistency Methods 73 Composition Arbitrary distributes over Constraints intersection PPC versus PC Algorithm Graph PC-p? Filtering PC-2 Complete PC-p Tight, not necessarily minimal PPC Triangulated PC-p Weaker filtering than PC-2 PC-2 Complete PC-p Minimal & Decomposable PPC Triangulated PC-p Minimal & Decomposable Foundations of Constraint Processing Basic Consistency Methods 74 PC: Special Case • Distributivity property – Outer loop in PC-1 (PC-3) can be ignored • Exploiting special conditions in temporal reasoning – Temporal constraints in the Simple Temporal Problem (STP): composition & intersection – Composition distributes over intersection • PC-1 is a generalization of the Floyd-Warshall algorithm (all pairs shortest path) – Convex constraints • PPC Foundations of Constraint Processing Basic Consistency Methods 75 Distributivity property Intersection, In PC-1, two operations: Composition, • B RAB A RBC R’BC C RAB • (RBC R'BC) = (RAB • RBC) (RAB • R’BC) When ( • ) distributes over ( ), then [Montanari'74] 1. PC-1 guarantees that CSP is minimal and decomposable 2. The outer loop of PC-1 can be removed Foundations of Constraint Processing Basic Consistency Methods 76 Condition does not always hold Constraint composition does not always distribute over constraint intersection •R12= 10 10 R23= 01 00 R’23= 10 00 • 11 00 •( ⋅( ⋅ 11 00 ∩ 00 10 00 10 )= )∩( 00 00 11 00 ⋅ 10 00 ⋅ 11 00 00 00 = )= 10 00 ∩ 10 00 = 10 00 10 00 Foundations of Constraint Processing Basic Consistency Methods 77 Temporal Reasoning constraints of bounded difference Variables: X, Y, Z, etc. Constraints: a Y-X b, i.e. Y-X = [a, b] = I Composition: I 1 • I2 = [a1, b1] • [a2, b2] = [a1+ a2, b1+b2] Interpretation: – intervals indicate distances – composition is triangle inequality. Intersection: I1 I2 = [max(a1, a2), min(b1, b2)] Distributivity: I1 • (I2 I3) = (I1 • I2) (I1 • I3) Proof: left as an exercise Foundations of Constraint Processing Basic Consistency Methods 78 Example: Temporal Reasoning Composition of intervals + : R’13 = R12 + R23 = [4, 12] R01 + R13 = [2,5] + [3, 5] = [5, 10] V0 R01 + R'13 = [2,5] + [4, 12] = [6, 17] V2 R12=[3,4] R01=[2,5] V1 R23=[1,8] R’13 V3 R13 =[3,5] Intersection of intervals: R13 R'13 = [4, 12] [3, 5] = [4, 5] R01 + (R13 R'13) = (R01 + R13) (R01 + R'13) R01 + (R13 R'13) = [2, 5] + [4, 5] = [6, 10] (R01 + R13) (R01 + R'13) = [5, 10] [6,17] = [6, 10] Here, path consistency guarantees minimality and decomposability Foundations of Constraint Processing Basic Consistency Methods 79 Composition Distributes over • PC-1 generalizes Floyd-Warshall algorithm (allpairs shortest path), where – composition is ‘scalar addition’ and – intersection is ‘scalar minimal’ • PC-1 generalizes Warshall algorithm (transitive closure) – Composition is logical OR – Intersection is logical AND Foundations of Constraint Processing Basic Consistency Methods 80 Convex constraints: temporal reasoning (again!) Thanks to Xu Lin (2002) • Constraints of bounded difference are convex • We triangulate the graph (good heuristics exist) • Apply PPC: restrict propagations in PC to triangles of the graph (and not in the complete graph) • According to [Bliek & Sam-Haroud 99] PPC becomes equivalent to PC, thus it guarantees minimality and decomposability Foundations of Constraint Processing Basic Consistency Methods 81 Summary 1. Alert: Do not confuse a consistency property with the algorithms for reinforcing it 2. Local consistency methods – – – – – Remove inconsistent values (node, arc consistency) Remove Inconsistent tuples (path consistency) Get us closer to the solution Reduce the ‘size’ of the problem & thrashing during search Are ‘cheap’ (i.e., polynomial time) 3. Global consistency properties are the goal we aim at 4. Sometimes (special constraints, graphs, etc) local consistency guarantees global consistency – E.g., Distributivity property in PC, row-convex constraints, special networks 5. Sometimes enforcing local consistency can be made cheaper than in the general case – E.g., functional constraints for AC, triangulated graphs for PC Foundations of Constraint Processing Basic Consistency Methods 82