1.09k likes | 1.24k Views
Reasoning with global constraints. Christian Bessiere LIRMM (CNRS/U. Montpellier) France. Background. Constraint networks. A set X={X1,…,Xn} of variables A set D={D(X1),…D(Xn)} of domains, where D(Xi) is the finite set of values for Xi A set C={C1,…Ce} of constraints.
E N D
Reasoning with global constraints Christian Bessiere LIRMM (CNRS/U. Montpellier) France
Constraint networks • A set X={X1,…,Xn} of variables • A set D={D(X1),…D(Xn)} of domains, where D(Xi) is the finite set of values for Xi • A set C={C1,…Ce} of constraints
Agreements on domains • Domains are given in extension to allow any type of reasoning If ||D(Xi)|| denotes the size of the encoding, ||D(Xi)|| = |D(Xi)| • Example: • D(X)={1,..,100} • ||D(X)|| = 100 (not log2(100))
Agreements on domains • Domains are subsets of the set Z of integers We inherit the total ordering on integers • Example: • D(X)={1,..,100} • Special values: min(X)=1, max(X)=100
ub(S) S1:{1} S2:{1} S3:{0,1} S4:{0,1} S5:{0} lb(S) 1 2 3 4 1 2 Set variables • It is sometimes convenient to consider a Boolean vector <S1,…,Sn> as a set variable S with domain 2{1..n} • In this case, D(S) is represented by its required values lb(S) and possible values ub(S) S can take values: {1,2}, {1,2,3}, {1,2,4}, {1,2,3,4} [Gervet94]
Y X 1 2 4 7 9 3 7 8 10 Constraints • A constraint c specifies the allowed combinations of values on a sequence X(c)=(Xi1,…,Xiq) of variables • Classical definition in CSPs: • c D(Xi1) x ... X D(Xiq) • Example: • c X < Y D(X)={3, 7, 8, 10} D(Y)={1, 2, 4, 7, 9} c={(3,4), (3,7), (3,9), (7,9), (8,9)}
1 2 4 7 9 3 7 8 10 …Not satisfactory • because it does not fit what is done in practice: X < Y is not encoded as a set of pairs! • And even if it was, we do not want to remove all pairs (v,w) from c each time a value v is removed from D(X) because it does not permit to express all types of local consistencies (see bound consistency in [Dechter03])
Constraints • A constraint c specifies the allowed combinations of values on a sequence X(c)=(Xi1,…,Xiq) of variables c Z|X(c)| c = {allowed tuples on X(c)} c is independent of the effective domains of its variables So, a constraint c is defined by any Boolean function fc with domain Z|X(c)| c X < Y is the set {…(-11,-7),…, (0,4), (0,5), (0,6),…, (7,9), (7,10)…} of all tuples (v,w) where v<w.
Non-binary versus global constraints • Non-binary: c with scope X(c), |X(c)|>2 • Global constraint: class G of constraints defined by a Boolean function fG with domain Z* • alldiff : fG(t)=1 iff v,w t, v w • A constraint c on X(c) belongs to a class G iff c = {t Z|X(c)| | fG(t)=1} • Alldiff(X1,X2,X3)= {t Z3 | t[1] t[2], t[1] t[2], t[2] t[3]} Restriction: checking if fG(t)=1 is polynomial
Some global constraints • Nvalue(X1..Xn,N) number of values taken by Xi’s is equal to N • (2,1,3,3, 3) is allowed • Alldiff(X1..Xn) Nvalue(X1..Xn,n) • Atmost[k,v](X1..Xn) at most k variables take value v • (2,5,1,4) is allowed if k=2, v=2 • See Beldiceanu’s catalog (>200 global constraints) [Bel&al05]
Do we need global constraints? • …or at least: ‘do we need all of them when specifying a CP toolkit?’ • Why global constraints? • Expressiveness (semantic globality) expressing new things • Effectiveness of propagation (operational globality) producing powerful effects • Efficiency of propagation (algorithmic globality) producing the result with little wasted effort [BesVanH03]
Expressiveness • Global constraints permit a high-level programming approach: a whole pattern in a single constraint • Allowed shifts in a nurse rostering • Strech constraint: at most 5 working days and not morning after night • N N R R M M A A A A R N M M R R • But are they all necessary? • does each permit to express what others can’t? [Pesant04]
Early work • Encode non-binary constraints as binary ones • Primal representation • Hidden representation • Dual representation [Montanari74, DecPea89, Jan&al89, Dechter90, Ros&al90]
X1 X2 X3 X4 Early work: Primal graph • Keep the same variables/domains • Replace non-binary constraints by their binary projections (inside DX(c)) • Alldiff(X1,..X4): • sol(N)=alldiff(X1..X4)
sol(N)= 13 15 17 35 37 X X Y Z 1 2 3 1 2 5 1 4 5 1 4 7 1 6 7 3 2 5 3 4 7 12 14 16 32 34 X+Y=Z 1 2 3 1 4 5 1 6 7 3 2 5 3 4 7 Z 23 25 45 47 67 Y Early work: Primal graph • But, it does not always work • X + Y = Z with D(X)={1, 2, 3} D(Y)={2, 4, 6} D(Z)={1, 3, 5, 7}
Hc Z • 3 • 145 5 • 167 7 • 325 5 • 347 7 Hc2 W Early work: Hidden repr. • Keep the original variables • Add a new variable Hc for each original constraint c • D(Hc)={t | t c DX(c)} • Binary constraints between Hc and Xi X(c) that accept (t,v) iff t[Xi]=v Hc X Y Z
Early work: Hidden repr. • D(Hc)={t | t c DX(c)} |D(Hc)|O(dk) • Exponential size of the representation
Vc1 123 145 167 325 347 Vc2 475 655 675 676 Vc1 Vc2 c1 W c2 X Y Z Early work: Dual repr. • Forget original variables • Add a new variable Vc for each original constraint c • D(Vc)={t | t c DX(c)} • X(c1) X(c2) c(Vc1,Vc2) • (t1,t2) c(Vc1,Vc2) iff t1[X(c1)X(c2)] = t2[X(c1)X(c2)] Y+Z>2W, D(W)={5,6}
Early work: Dual repr. • D(Vc)={t | t c DX(c)} |D(Vc)|O(dk) • Exponential size of the representation
Semantic globality (relative to L) • When does a global constraint help expressing something new in a language L? If it cannot be polynomially decomposed with constraints in L
A sample language • Range, Roots, and basic arithmetic primitives [Comics05]
S T A sample language • Range(X1,...,Xn,S,T) X(S)=T, where X({i})=Xi 1 v1 vj i n vm
S S T T A sample language • Roots(X1,...,Xn,S,T) S=X-1(T)
Semantic globality (relative to L) • When does a global constraint help expressing something new in a language L? • If it cannot be polynomially decomposed with constraints in L • On the same variables • With extra variables
Decomposition (relative to L) • alldiff(X1,..,Xn): • Atmost[1,1](X1,..,Xn) • Atmost[1,2](X1,..,Xn) • Atmost[1,3](X1,..,Xn) • … • Atmost[1,v](X1,..,Xn), vD(Xi), i
X1 X2 X3 X4 1 1 2 2 2 2 3 3 3 3 4 4 5 5 S={2,3,4} S={} Decomposition with extra variables (relative to L) • atmost[k,v](X1,..Xn) ( k=2, v=2 ) X1…X4 1 1 2 2 1 1 2 3 … 1 2 2 2 … 2 2 2 2 … 4 4 5 5 |S|>k Roots(X1,..Xn,S,{v}) |S|k atmost is decomposable in L |S|≤k
X1…X4 N 1 1 2 2 2 1 1 2 3 3 1 1 2 5 3 … 1 2 3 5 4 … 4 4 5 5 2 1 2 3 4 5 T X1 X2 X3 X4 X1 X2 X3 X4 1 1 2 2 2 2 3 3 3 3 4 4 5 5 Decomposition with extra variables (relative to L) • Nvalue(X1,..Xn,N) N 1 2 3 4 Range(X1,..Xn,{1..n},T) |T|=N Nvalue is decomposable in L
Decomposition relative to L • G decomposable relative to L if: • c G, D on X(c), N=(X(c)Y,D’,C) such that • XiX(c), D’(Xi)=D(Xi) • c’ C, c’ L • sol(N)[X(c)] = sol(X(c),D,{c}) • ||N|| is poly in ||c||+||D||
Absolute semantic globality • When does a global constraint help expressing something new? (independently of any language) If it cannot be polynomially decomposed with constraints of bounded arity • On the same variables • With extra variables
Absolute decomposition • G k-decomposable if • c G, D on X(c), N=(X(c)Y,D’,C) such that • XiX(c), D’(Xi)=D(Xi) • c’ C, |X(c’)| k • sol(N)[X(c)] = sol(X(c),D,{c}) • ||N|| is poly in ||c||+||D|| • G is decomposable if k s.t. G is k-decomposable
X1 X2 X3 X4 Absolute decomposition • Alldiff clique of binary inequalities • Alldiff(X1..X4) Alldiff is decomposable
1 1 2 2 1 1 2 3 … 4 4 5 5 X1 X2 U U U U U U X3 X4 Absolute decomposition • Atmost[k,v](X1..Xn)? Atmost[3,2]: Atmost 3 among 4 atmost 3 among 3 universal constraint Atmost is not decomposable on the same variables
Absolute decomposition with extra variables • Atmost[k,v](X1..Xn): • B0…Bn, D(Bi)={0,…,n} • (Xi=v & Bi=Bi-1+1)(Xiv & Bi = Bi-1), i • B0=0, Bn k X1 X2 Xi …… Xn-1 Xn B0 B1 Bi-1 Bi …… Bn-1 Bn atmost is 3-decomposable
X1 X2 Xi …… Xn-1 Xn Y0 Y1 Yi-1 Yi …… Yn-1 Yn Absolute decomposition with extra variables • c (Xi = k): • Y0…Yn, D(Yi)={0,…,k} • Yi = Yi-1+Xi, i • Y0=0, Yn = k ||D(Yi)|| exponential in ||(X,D,{c}) || Xi = k is not decomposable
X Y Z 1 2 1 2 4 3 3 6 5 7 Reasoning with global constraints c is X+Y=Z • All CP solvers propagate constraints • ‘propagate’ usually means: remove value v in D(Xi), XiX(c) if not tc, t[Xi]=v and t[Xj]D(Xj) j • This is the maximum amount of inconsistency information a constraint taken alone can project on a variable, aka: Generalized Arc Consistency (GAC )
X + Y = Z 1 2 1 2 4 3 3 6 5 7 Questions related to GAC • GACSupport[c,D,X,v]: • Does value v for X have a support on c in D? • GACSupport[X,1]? yes • GACSupport[X,2]? no
X + Y = Z 1 2 1 2 4 3 3 6 5 7 Questions related to GAC • IsItGAC[c,D]: • Does GACSupport[c, D, X, v] answer ‘yes’ for each X X(c) and each value v D(X)? • IsItGAC[D]? no • IsItGAC[D1]? yes
X + Y = Z 1 2 1 2 4 3 3 6 5 7 Questions related to GAC • NoGACWipeOut[c,D]: • Is there any non empty D’ D on which IsItGAC[D’] answers yes? • NoGACWipeOut[D]? yes • NoGACWipeOut[D2]? no
X + Y = Z 1 2 1 2 4 3 3 6 5 7 Questions related to GAC • maxGAC[c,D’,D]: • Is it the case that IsItGAC[c, D’] answers ‘yes’ and not D’’, D’ D’’ D such that IsItGAC[D’’]? • maxGAC[D,D]? no • maxGAC[D1,D]? no
X + Y = Z 1 2 1 2 4 3 3 6 5 7 Questions related to GAC • maxGAC[c,D’,D]: • Is it the case that IsItGAC[c, D’] answers ‘yes’ and not D’’, D’ D’’ D such that IsItGAC[D’’]? • maxGAC[D,D]? no • maxGAC[D1,D]? no • maxGAC[D3,D]? yes
X + Y = Z 1 2 1 2 4 3 3 6 5 7 Questions related to GAC • GACDomain[c,D]: • The domain D’ such that maxGAC[D’,D] answers yes • GACDomain[D]? D3
GAC reasoning is intractable • GACSupport is in NP (poly certificate) • Let G be the class of constraints defined by X1 , where is a 3Sat formula • GACSupport(c,{0,1}n,X,1) solves the SAT problem GACSupport is NP-complete
GAC reasoning is intractable • GACSupportis NP-complete • IsItGACis NP-complete • NoGACWipeOutis NP-complete • GACDomainis NP-hard • maxGAC?
maxGAC is DP-complete • A decision problem P is DP-complete iff there exists two problems Q1 (NP-c) and Q2 (coNP-c) such that P answers ‘yes’ when Q1 answers ‘yes’ and Q2 answers ‘no’ • Let G1 and G2 be two 3Col problems (on the nodes s1..sn): X1 X2 …… Xn 1,2,3 1,2,3 1,2,3 4,5,6 4,5,6 4,5,6 c(Xi,Xj) forbids (v,w) if v(1,2,3) and w(4,5,6) or vice versa (si,sj) G1 c(Xi,Xj) forbids (11), (22), (33) on Xi,Xj (si,sj) G2 c(Xi,Xj) forbids (44), (55), (66) on Xi,Xj • maxGAC(c,{1..3}n,{1..6}n) answers yes iff G1 is 3colorable and G2 is not
Questions related to GAC • Let G be a class of constraints • GACSupport(G) • IsItGAC(G) • NoGACWipeOut(G) • maxGAC(G) • GACDomain(G) …are the same as before but constraints must belong to G
Dependencies between GAC questions • Suppose GACSupport(G) is NP-complete • NoGACWipeOut is in NP • GACSupport(G)[c,D,X,v] can be solved by a call to NoGACWipeOut(G)[c,DX=v] NoGACWipeOut(G) is NP-complete