Title: Reasoning with global constraints
1Reasoning with global constraints
- Christian Bessiere
- LIRMM (CNRS/U. Montpellier)
- France
2Background
3Constraint networks
- A set XX1,,Xn of variables
- A set DD(X1),D(Xn) of domains, where D(Xi) is
the finite set of values for Xi - A set CC1,Ce of constraints
4Agreements 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))
5Agreements 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
6Set variables
- It is sometimes convenient to consider a Boolean
vector ltS1,,Sngt as a set variable S with domain
21..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
7Constraints
- 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 lt 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)
8Not satisfactory
- because it does not fit what is done in practice
X lt 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)
9Constraints
- A constraint c specifies the allowed
combinations of values on a sequence
X(c)(Xi1,,Xiq) of variables
- c ? ZX(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 ZX(c)
c ? X lt Y is the set (-11,-7),, (0,4), (0,5),
(0,6),, (7,9), (7,10) of all tuples (v,w)
where vltw.
10Non-binary versus global constraints
- Non-binary c with scope X(c), X(c)gt2
- 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 ? ZX(c) fG(t)1 - Alldiff(X1,X2,X3)
t ? Z3 t1 ?
t2, t1 ? t2, t2 ? t3
Restriction checking if fG(t)1 is polynomial
11Some global constraints
- Nvalue(X1..Xn,N) ? number of values taken by Xis
is equal to N - (2,1,3,3, 3) is allowed
- Alldiff(X1..Xn) ? Nvalue(X1..Xn,n)
- Atmostk,v(X1..Xn) ? at most k variables take
value v - (2,5,1,4) is allowed if k2, v2
- See Beldiceanus catalog (gt200 global constraints)
Belal05
12Do 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
13Part 1 Semantic Globality
14Expressiveness
- 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 cant?
Pesant04
15Early work
- Encode non-binary constraints as binary ones
- Primal representation
- Hidden representation
- Dual representation
Montanari74, DecPea89, Janal89, Dechter90,
Rosal90
16Early 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)
17Early 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
18Early 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 tXiv
Hc
X
Y
Z
19Early work Hidden repr.
- D(Hc)t t ? c ? DX(c) ?
D(Hc)?O(dk) - Exponential size of the representation
20Early 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
t1X(c1)?X(c2) t2X(c1)?X(c2)
YZgt2W, D(W)5,6
21Early work Dual repr.
- D(Vc)t t ? c ? DX(c) ?
D(Vc)?O(dk) - Exponential size of the representation
22Semantic 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
23A sample language
- Range, Roots, and basic arithmetic primitives
Comics05
24A sample language
- Range(X1,...,Xn,S,T) ? X(S)T, where X(i)Xi
1
v1
vj
i
n
vm
25A sample language
- Roots(X1,...,Xn,S,T) ? SX-1(T)
26Semantic 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
27Decomposition (relative to L)
- Atmost1,1(X1,..,Xn)
- Atmost1,2(X1,..,Xn)
- Atmost1,3(X1,..,Xn)
-
- Atmost1,v(X1,..,Xn), ?v?D(Xi), ?i
28Decomposition with extra variables (relative to L)
- atmostk,v(X1,..Xn) ( k2, v2 )
X1X4
1 1 2 2 1 1 2 3 1 2 2 2 2 2 2 2 4 4 5 5
Sgtk
Roots(X1,..Xn,S,v) ? S?k
atmost is decomposable in L
Sk
29Decomposition with extra variables (relative to L)
N 1 2 3 4
Range(X1,..Xn,1..n,T) ? TN
Nvalue is decomposable in L
30Decomposition relative to L
- G decomposable relative to L if
- ?c ? G, ?D on X(c), ?N(X(c)?Y,D,C) such
that - ?Xi?X(c), D(Xi)D(Xi)
- ?c ? C, c ? L
- sol(N)X(c) sol(X(c),D,c)
- N is poly in cD
31Absolute 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
32Absolute decomposition
- G k-decomposable if
- ?c ? G, ?D on X(c), ?N(X(c)?Y,D,C) such that
- ?Xi?X(c), D(Xi)D(Xi)
- ?c ? C, X(c) ? k
- sol(N)X(c) sol(X(c),D,c)
- N is poly in cD
- G is decomposable if
- ?k s.t. G is k-decomposable
33Absolute decomposition
- Alldiff ? clique of binary inequalities
- Alldiff(X1..X4)
Alldiff is decomposable
34Absolute decomposition
- Atmost 3 among 4 ? atmost 3 among 3 ? universal
constraint
Atmost is not decomposable on the same variables
35Absolute decomposition with extra variables
- Atmostk,v(X1..Xn)
- B0Bn, D(Bi)0,,n
- (Xiv BiBi-11)?(Xi?v Bi Bi-1), ?i
- B00, Bn ? k
X1 X2 Xi Xn-1 Xn
B0 B1 Bi-1 Bi Bn-1 Bn
atmost is 3-decomposable
36Absolute decomposition with extra variables
- c ? (?Xi k)
- Y0Yn, D(Yi)0,,k
- Yi Yi-1Xi, ?i
- Y00, Yn k
D(Yi) exponential in (X,D,c)
?Xi k is not decomposable
37Part 2 Complexity of Reasoning
38Reasoning with global constraints
c is XYZ
- All CP solvers propagate constraints
- propagate usually means
- remove value v in D(Xi), Xi?X(c) if
- not ?t?c, tXiv and tXj?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 )
39Questions related to GAC
- GACSupportc,D,X,v
- Does value v for X have a support on c in D?
? yes
? no
40Questions related to GAC
- IsItGACc,D
- Does GACSupportc, D, X, v answer yes for each
X ? X(c) and each value v ? D(X)?
? no
? yes
41Questions related to GAC
- NoGACWipeOutc,D
- Is there any non empty D ? D on which
IsItGACD answers yes?
? yes
? no
42Questions related to GAC
- maxGACc,D,D
- Is it the case that IsItGACc, D answers yes
and not ? D, D ? D ? D such that
IsItGACD?
? no
? no
43Questions related to GAC
- maxGACc,D,D
- Is it the case that IsItGACc, D answers yes
and not ? D, D ? D ? D such that
IsItGACD?
? no
? no
? yes
44Questions related to GAC
- GACDomainc,D
- The domain D such that maxGACD,D answers yes
- GACDomainD?
? D3
45GAC 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,1n,X,1) solves the SAT problem
- ? GACSupport is NP-complete
46GAC reasoning is intractable
- GACSupport is NP-complete
- IsItGAC is NP-complete
- NoGACWipeOut is NP-complete
- GACDomain is NP-hard
- maxGAC?
47maxGAC 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..3n,1..6n) answers yes iff
- G1 is 3colorable and G2 is not
48Complexity summary
Problem Complexity class
GACSupport NP-complete
IsItGAC NP-complete
NoGACWipeOut NP-complete
GACDomain NP-hard
maxGAC DP-complete
49Questions 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
50Dependencies 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,DXv - ? NoGACWipeOut(G) is NP-complete
51Dependencies between GAC questions
NoGACWOut
GACSupport
IsItGAC
GACDomain
maxGAC
A NP-hard ? B NP-hard
B
A
52A question related to GAC Entailment
- Entailment captures the idea that a constraint is
no longer necessary in the network, that is, for
any subdomain D of D, c is GAC - Entailedc,D
- Is DX(c) ? c ?
- Example
- c ? (X ? Y ? Z)
X ? Y ? Z 1 2 1
2 4 3
3 6 5
53Entailment is intractable
- If there is a single tuple in D violating c,
Entailed(c,D) is false - ? there is a tuple satisfying the negation nc of
c - So, Entailed(c,D) ? NoGACWipeOut(nc,D)
- Entailed is coNP-complete
54Part 3 Operational Globality
55Do we need global constraints?
- Expressiveness
- Effectiveness of propagation
- ?producing powerful effects
- Efficiency of propagation
- ?producing the result with little wasted effort
56Effectiveness of propagation
- Global constraints give a global view on what
values are consistent or not - But are they all necessary?
- do they permit to rule out values decompositions
cannot?
57Early work decomposability of Montanari
- A constraint c is M-representable iff
- its primal graph N(X(c),D,C) is such that
sol(X(c),D,C)c (ie, 2-decomp on the same vars)
Alldiff is M-representable
Montanari74
58Early work decomposability of Montanari
- A constraint c is M-decomposable iff
- ?Y?X(c), sol(X(c),D,C)Y is M-representable
(1,2,3) is accepted whereas it does not
extend to X4
Alldiff is not M-decomposable
59Early work decomposability of Montanari
- If a constraint c is M-decomposable into
N(X(c),D,C) then N is globally consistent - ? AC on N is equivalent to GAC on c
60Early work decomposability of Montanari
- This condition is too restrictive
- Eg, it is well-known that if N is tree
structured, AC prunes all non consistent values
1 2 3
1 2 3
1 2 3
lt
1 2 3
lt
61Early work tree structure
- If a global constraint G can be decomposed as a
tree-structured binary network N then GAC(c) is
equivalent to AC(N) - Allequal(X1,..X4)
- GAC(c)AC(N)
Genal00
62Operational globality
- When do global constraints help propagating
something more? - If all decompositions in L hinder propagation
- If all absolute decompositions hinder propagation
63Operational globality (wrt L)
GAC on alldiff prunes values 2 and 3 from X1,X2
because D(X3)D(X4)2,3
- alldiff(X1,..,Xn)
- Atmost1,1(X1,..,Xn)
- Atmost1,2(X1,..,Xn)
- Atmost1,3(X1,..,Xn)
Decomposition hinders GAC
64Operational globality (wrt L)
k2, v2
GAC on atmost prunes value 2 from X1,X2 because
there exist 2 variables X3 and X4 with D2
Roots(X1,..Xn,S,2) ? S?2
? Roots puts 3 and 4 in lb(S)
- S?2 removes 1 and 2 from ub(S)
? Roots prunes 2 from X1, X2
Decomposition preserves GAC
65Operational globality (wrt L)
- Nvalue(X1,..Xn,N) with N1
Range(X1,..Xn,1..n,T) ? TN
? T ? 1,2,3,4,5
and both constraints are AC
whereas all 1, 4, and 5 should be pruned from
Xis
Decomposition hinders GAC
66Operational globality
- When do global constraints help propagating
something more? - If all decompositions in L hinder propagation
- If all absolute decompositions hinder propagation
67Absolute operational globality
- Alldiff is decomposable but
1,2,3,4
2,3
?
1,2,3,4
?
2,3
?
?
?
?
1,2,3,4
2,3
2,3
1,2,3,4
alldiff
Decomposition hinders GAC
68Absolute operational globality
X1 X2 X3 Xn-1 Xn
B0 B1 B2 B3 Bn-1 Bn
- B0Bn, D(Bi)0,,n
- (Xiv BiBi-11)?(Xi?v Bi Bi-1), ?i
- Bn ? k
69Operational globality
- When do global constraints help propagating
something more? - If all decompositions in L hinder propagation
- If all absolute decompositions hinder propagation
- Relaxing absolute decomposition
70Relaxing absolute decomposition
- Absolute decomposition requires bounded arity
(this was necessary from the semantic point of
view) - Relaxation Let LP be the language of all
constraints on which GAC is polynomial - G is GAC-poly-time decomposable iff there exists
a decomposition of G wrt LP that does not hinder
propagation - How to know which constraints are decomposable?
Comics04
71Using computational complexity
- Computational complexity can help deciding the
existence of decompositions that preserve GAC - If NoGACWipeOut(G) is NP-complete, then there
does not exist any GAC-poly-time decomposition
for G
72Example
- Our decomposition of Nvalue Range(X1,..Xn,1..n
,T) ? TN hinders GAC - Nvalue(X1,..Xn,n) is polynomial to propagate (?
alldiff) - What about Nvalue(X1,..Xn,N), where N is a
variable?
73Reduction of 3Sat
- Let ? be a 3Sat formula on x1..xn with m clauses
- Xi?-i,i, ?i?1..n
- Xnj ?f,-g,h, ?cjxf?? xg? xh ? ?
- N ? n
- Nvalue(X1,,Xn,Xn1,, Xnm,N) has a solution iff
? is satisfiable
Nvalue cannot be GAC-poly-time decomposed
X1 Xi Xn Xn1 Xnj
Xnm
-1 1
-i i
f -g h
-n n
74Do we need global constraints?
- Expressiveness
- Effectiveness of propagation
- ?producing powerful effects
- Efficiency of propagation
- ?producing the result with little wasted effort
75Efficiency of propagation
- Does GAC have the same complexity on
decomposition and on the original constraint? - Example Range can be encoded as a Gcc
constraint, but GAC on Gcc is more expensive than
on Range - ? Algorithmic globality
Regin96,Comics06
76So what?
- If a constraint has some inherent globality
- Semantic no way to escape!
- Operational do we accept losing pruning?
- Algorithmic do we accept a slow-down?
- Otherwise
- ? write a specific algorithm (see other talks)
- ? use a generic GAC algorithm
77Part 4 Generic Algorithms
78GAC3
- GAC3(X,D,C)
- Q ? (Xi,c) c ? C and Xi ? X(c)
- While Q ? ? do
- Pick (Xi,c) from Q
- If Revise(Xi,c) then
- If D(Xi) ? then return False
- Update Q
- Return True
Revise(Xi,c) Change ? False For each vi ? D(Xi)
do t ? seekSupport(Xi, vi, c) If tnil then
remove vi from D(Xi) Change ? True Return
Change
Mackworth77
79Space of tuples
XYZ
D(X)1,2,3 D(Y)1,2 D(Z)3,4,5
80seekSupport
XYZ
seekSupport(X,1)
81seekSupport
XYZ
seekSupport(Y,1)
1
2
3
82GAC3
seekSupport O(dk-1) checks
Nb of calls O(kd) per change
- GAC3(X,D,C)
- Q ? (Xi,c) c ? C and Xi ? X(c)
- While Q ? ? do
- Pick (Xi,c) from Q
- If Revise(Xi,c) then
- If D(Xi) ? then return False
- Update Q
- Return True
Revise(Xi,c) Change ? False For each vi ? D(Xi)
do t ? seekSupport(Xi, vi, c) If tnil then
remove vi from D(Xi) Change ? True Return
Change
Number of checks O(k2dk1)
83Techniques used to be efficient
84Ordering Last
XYZ
seekSupport(Z,4)
Last(Z,4)
Last(Z,4)
85GAC2001
Revise2001(Xi,c) Change ? False For each vi ?
D(Xi) do if Last(Xi,vi,c) non valid then t ?
seekNextSupport(Xi,vi,c,Last) If tnil then
remove vi from D(Xi) Change ? True Else
Last(Xi,vi,c) ? t Return Change
Revise(Xi,c) Change ? False For each vi ? D(Xi)
do t ? seekSupport(Xi, vi, c) If tnil then
remove vi from D(Xi) Change ? True Return
Change
O(dk-1) per value
Number of checks O(kdk)
Besal01
86Techniques used to be efficient
- Ordering Last support
- Multidirectionality
- What does it mean?
- If a tuple t((X,v),(Y,w),) has been found (not
to) to support (X,v), it also (doesnt) supports
(Y,w)
87Using multidirectionality
- Do not check a tuple t if t has already been
checked before - Do not look for support for (Xi,v) if a tuple
supporting it has already been checked
88Using multidirectionality
- Do not check a tuple t if t has already been
checked before - Observe that if t has been checked when looking
for support for (Xi,v), Last(Xi,v) guarantees it
wont be checked again by seekNextSupport(Xi,v) - what about seekNextSupport(Xj,w)?
- ? GAC2001 doesnt ensure (1)
89GAC-schema
seekNextSupport(Z,4)
Last(Z,4)
BesRég97
90Using multidirectionality
- Gddf
- Do not look for support for (Xi,v) if a tuple
supporting it has already been checked ?
Last is not enough - GAC-schema ensures (2) thanks to its fine-grained
data structure - St set of values supported by t
- SCXi,v set of supporting tuples containing
(Xi,v)
91GAC-schema
seekNextSupport(Xi,v)
Xi
Xj
seekNextSupport(Xj,w)?
v2 w
v w
t
92GAC-schema
- Ordering Last support
- Multidirectionality
Number of checks O(dk)
the best complexity (like GAC4 which reads all
tuples in advance)
93GAC-schema
- We always supposed that a constraint check is
polynomial - This is true when c is defined by a function fc
- But what happens with Table constraints? (ie, a
list of allowed tuples)
94Table constraints
- Use GAC4 ? heavy updates of his huge lists
- Use GAC-schematable
- It looks for valid tuples in the table T(c)
instead of allowed tuples in D(X1) x x D(Xk) - ? It can explore an exponential number of tuples
in the table which are no longer valid - Use GACallowed
- It jumps from T(c) to DX(c) and from DX(c) to T(c)
LhoReg05,LecSym06
95Alternatives binary encodings
- AC on hidden representation
- AC on dual representation
96AC on hidden representation
- AC(hidden) ? GAC(c)
- Specialized AC-hidden algorithm
- It requires updating the (exponential) hidden
domain (? GAC4)
SamSte04
97AC on dual representation
- AC(dual) ? Pairwise consistency
WipeOut(GAC) ? WipeOut(PW)
Beeal83,Janal89
98Part 5 Other levels of consistency
99Weaker levels of consistency
- Bound consistency was first introduced for
arithmetic constraints on real variables - Several adaptations to finite domain variables
- The most common (and most interesting) is BC(Z),
which gets rid of domain size - The others BC(D), RangeC explore domains,
BC(R) is trivial on most constraints
Apt03,Dechter03,Choal05,Bessiere05
100BC(Z)
- Definition
- A tuple t on c is a bound support iff t?c
and
min(Xi) ? tXi ? max(Xi), ?Xi ? X(c) - Xi is bound consistent on c iff ?
bound supports t, t such that tXimin(Xi) and
tXimax(Xi)
101Bound consistency(Z)
Y X2
X -1 0 1 2 3
Y 0 3 4
BC(Z)
GAC
102Bound consistency(Z)
- Decomposability analysis for BC(Z)?
- It depends on domains representation
- When reasoning with BC, it is often the case that
we accept domains represented as intervals - ? It changes the size of the encoding!
103Effect of the size
D(Yi) polynomial in (X,D,c) if domains
are encoded as intervals
- c ? (?Xi k)
- Y0Yn, D(Yi)0k
- Yi XiYi-1, ?i
- Y00, Yn k
? ?Xi k is decomposable on intervals
- In addition, BC(Z) on the decomposition is
equivalent to BC(Z) on ?Xi k - So, ?Xi k is BC-poly-time decomposable
- (remember it was not GAC-poly-time decomposable)
104Effect of the size (2)
Y
1 2n
X
- BC(Z) can require an exponential number of checks
even if the domain is small - Let c(X,Y) be the constraint that accepts (v,w)
iff v0 or (w mod 2n)base_2 is a model of 3Sat
formula ? - If D(X)0,1 and D(Y)1, 2n, checking BC(Z) on
(X,1) is equivalent to solving SAT(?) - ? BC(Z) is NP-hard whereas GAC takes 3
checks!
0 1
?
01101001
105Stronger levels of consistency
Pairwise consistency
- Reasoning on several constraints at a time
- Often requires deleting tuples in constraints
(pairwise, relational) - ? Exponential size and makes propagation difficult
DecvanB95
106Stronger levels of consistency
- We can adapt inverse consistencies of the binary
case - Relational PIC, P(air)W(ise)IC
- WipeOut(PWIC) iff WipeOut(GAC(PW))
- Efficient algorithm for PWIC beats GAC quite
often
FreElf96,SteWal06
107The end