8
Theory and Practice of Constraint Propagation Roman Barták * Charles University, Faculty of Mathematics and Physics Malostranské námestí 2/25, 118 00 Praha 1, Czech Republic e-mail: [email protected] Abstract: Despite successful application of constraint programming (CP) to solving many real-life problems there is still an indispensable group or researchers considering (wrongly) CP as a simple evaluation technique only. Even if sophisticated search algorithms play an important role in solving constraint-based models, the real power engine behind CP is called constraint propagation (domain filtering, pruning or consistency techniques). In the paper we give a survey of common consistency techniques for binary constraints. We describe the main ideas behind them, list their advantages and limitations, and compare their pruning power. Then we briefly explain how these techniques can be extended to non-binary constraints. Last part of the paper is devoted to modelling issues. We give some hints how the constraint propagation can be exploited more when solving real-life problems. This part is based on our experience with solving real-life programs and it is also supported by empirical observations of other researchers. Keywords: constraint propagation, filtering algorithms * Supported by the Grant Agency of the Czech Republic under the contracts no. 201/99/D057 and 201/01/0942 and by the project LN00A056 of the Ministry of Education of the Czech Republic. 1 Introduction Thanks to many constraint satisfaction packages available for end users, constraint programming (CP) is becoming more widespread and CP technology is used to solve various mostly combinatorial problems. It means that there exists a growing group of users without deep knowledge how CP works inside but still able to model and solve problems by means of constraints. However, if difficulty of the problem increases then it is more and more complicated to design an appropriate constraint model that can then be successfully solved. We believe that better understanding of processes inside the constraint packages can help their users to design better models and thus to decrease development time (and expenses as well). Constraint satisfaction problem is defined by a finite set of variables, each variable has assigned a finite domain, i.e. a finite set of possible values, and by constraints restricting combinations of values that the variables can take together. The task is to find a value for each variable from its domain in such a way that all the constraints are satisfied. Usually, constraints are used actively to reduce domains by filtering values that cannot take part in any solution. This process is called constraint propagation, domain filtering, pruning or consistency technique, and it is the core of most constraint satisfaction packages. Constraint propagation can be used to solve fully the problem but this is rarely done due to efficiency issues. It is more common to combine an efficient but incomplete consistency technique with non- deterministic search. Such consistency technique does not remove all inconsistent values from the variables' domains, but it can still eliminate many "obvious" inconsistencies and, thus, simplify the problem and reduce the search space. To solve the problem to full-extent, incomplete consistency techniques are accompanied by non-deterministic search that explores possible value assignments. First, we show how a non-binary constraint can be translated to a set of binary constraints giving an equivalent solution set (Section2). Then, we survey basic consistency techniques for binary constraints (Section 3). In Section 4 we discuss some issues concerning non-binary constraints and techniques for solving them. Section 5 is devoted to some hints about using consistency techniques in practice. 2 Binary Constraints It is well known that a non-binary CSP, i.e., the CSP with constraints of arity larger than 2, can be translated to an equivalent binary CSP. This fact is so absorbed that many research papers dealing with constraint satisfaction methods assume binary In J. Figwer (editor) Proceedings of the 3 rd Workshop on Constraint Programming in Decision and Control, June 2001, Poland.

Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

Theory and Practice of Constraint Propagation

Roman Barták*

Charles University, Faculty of Mathematics and PhysicsMalostranské námestí 2/25, 118 00 Praha 1, Czech Republice-mail: [email protected]

Abstract: Despite successful application of constraint programming (CP) to solving many real-lifeproblems there is still an indispensable group or researchers considering (wrongly) CP as a simpleevaluation technique only. Even if sophisticated search algorithms play an important role insolving constraint-based models, the real power engine behind CP is called constraint propagation(domain filtering, pruning or consistency techniques).

In the paper we give a survey of common consistency techniques for binary constraints. Wedescribe the main ideas behind them, list their advantages and limitations, and compare theirpruning power. Then we briefly explain how these techniques can be extended to non-binaryconstraints. Last part of the paper is devoted to modelling issues. We give some hints how theconstraint propagation can be exploited more when solving real-life problems. This part is basedon our experience with solving real-life programs and it is also supported by empiricalobservations of other researchers.

Keywords: constraint propagation, filtering algorithms

* Supported by the Grant Agency of the Czech Republic under the contracts no. 201/99/D057 and 201/01/0942 and by the projectLN00A056 of the Ministry of Education of the Czech Republic.

1 IntroductionThanks to many constraint satisfaction packagesavailable for end users, constraint programming(CP) is becoming more widespread and CPtechnology is used to solve various mostlycombinatorial problems. It means that there exists agrowing group of users without deep knowledgehow CP works inside but still able to model andsolve problems by means of constraints. However,if difficulty of the problem increases then it is moreand more complicated to design an appropriateconstraint model that can then be successfullysolved. We believe that better understanding ofprocesses inside the constraint packages can helptheir users to design better models and thus todecrease development time (and expenses as well).

Constraint satisfaction problem is defined by afinite set of variables, each variable has assigned afinite domain, i.e. a finite set of possible values, andby constraints restricting combinations of valuesthat the variables can take together. The task is tofind a value for each variable from its domain insuch a way that all the constraints are satisfied.Usually, constraints are used actively to reducedomains by filtering values that cannot take part inany solution. This process is called constraintpropagation, domain filtering, pruning orconsistency technique, and it is the core of most

constraint satisfaction packages. Constraintpropagation can be used to solve fully the problembut this is rarely done due to efficiency issues. It ismore common to combine an efficient butincomplete consistency technique with non-deterministic search. Such consistency techniquedoes not remove all inconsistent values from thevariables' domains, but it can still eliminate many"obvious" inconsistencies and, thus, simplify theproblem and reduce the search space. To solve theproblem to full-extent, incomplete consistencytechniques are accompanied by non-deterministicsearch that explores possible value assignments.

First, we show how a non-binary constraint can betranslated to a set of binary constraints giving anequivalent solution set (Section2). Then, we surveybasic consistency techniques for binary constraints(Section 3). In Section 4 we discuss some issuesconcerning non-binary constraints and techniquesfor solving them. Section 5 is devoted to some hintsabout using consistency techniques in practice.

2 Binary ConstraintsIt is well known that a non-binary CSP, i.e., theCSP with constraints of arity larger than 2, can betranslated to an equivalent binary CSP. This fact isso absorbed that many research papers dealing withconstraint satisfaction methods assume binary

In J. Figwer (editor) Proceedings of the 3rd Workshop on Constraint Programming in Decision and Control, June 2001, Poland.

Page 2: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

constraints only and sometimes these methods arenever extended to n-ary constraints.

Projection. N-ary constraint can be easilyapproximated by binary constraints on the same setof variables by projecting the non-binary constraintonto the pairs of variables it contains [18]. Forsome n-ary constraints like all-different, this gives aset of binary constraints with the same solution setas the original n-ary constraint. Unfortunately, ingeneral we get a network of binary constraintshaving a set of solutions that is a superset of the setof solutions of the original non-binary constraint asFigure 1 shows. Still studying such binarydecomposition [13] is important because it allowsus to achieve some level of consistency on the n-aryconstraint, e.g. bound consistency, by making theset of binary constraints consistent.

Figure 1: Projection of the n-ary constraint onto the pairs ofvariables provides a superset of the original solution set.

There exist two basic general methods forconverting a non-binary CSP to an equivalentbinary CSP: the dual graph method and the hiddenvariable method. Both these methods change the setof variables of the original problem.

Dual encoding. The dual encoding is based onswapping the variables for constraints and viceversa. There is a dual variable vc for each n-aryconstraint c with the domain of consistent tuples ofthis constraints. For each pair of constraints c and c'sharing some variables in the original problem thereis a binary compatibility constraint between thevariables vc and vc'. This constraint restricts the dualvariables to tuples in which the original sharedvariables take the same value.

Figure 2: The dual variable encoding for the 0-1 variablesx1…x6 and the constraint problem c1:x1+x2+x6=1, c2:x1-x3+x4=1,c3:x4+x5-x6>0, c4:x2+x5-x6=0.

Hidden variable encoding. The hidden variableencoding uses the same dual variables vc like thedual encoding and, moreover, there are also theoriginal variables xi. The compatibility constraints

are defined between the dual variable vc and eachvariable xi in the constraint c. This constraintrestricts the tuples assigned to vc to be consistentwith the value assigned to xi.

Figure 3: The dual variable encoding for the 0-1 variablesx1…x6 and the constraint problem c1:x1+x2+x6=1, c2:x1-x3+x4=1,c3:x4+x5-x6>0, c4:x2+x5-x6=0.

Various levels of equivalence of these encodingwith the original non-binary problem are studied in[22]. Because of any non-binary constraint networkcan be polynomially converted into an equivalentbinary one, many works on filtering algorithms arerestricted to the binary case. However, in real-lifeproblems the binary conversion is sometimes/oftenimpracticable and therefore, recently severalresearchers turn attention to studying efficiency ofsuch conversion [1], comparing and proposing newbinary encodings [24,26] as well as dealing withnon-binary constraints directly [5-8].

3 Consistency techniques - a surveyIn the previous section, we showed that an arbitraryCSP can be translated to an equivalent binary CSP.For simplicity reasons we will use binary CSP toexplain ideas behind basic propagation algorithms.If the CSP is binary then it can represented as anundirected graph with the vertices corresponding tothe variables and the edges corresponding to theconstraints. Many names for the consistencytechniques are then derived from graph notions.

Node consistency. The easiest consistencytechnique called node consistency (NC) removesvalues inconsistent with unary constraints from thevariables' domains. The node consistency algorithmis pretty straightforward: it goes though thevariables and removes values inconsistent with anyunary constraint on the variable.

Arc consistency. We say that a constraint is arcconsistent (AC) if for any value of the variable inthe constraint there exists a value for the othervariable in such a way that the constraint issatisfied. CSP is arc consistent if all the constraintsare arc consistent. Usually, the constraint is madeAC by propagating the domain from one variable tothe other variable and vice versa. This is calledrevision of the (oriented) arc in the graph. CSP ismade AC by repeated revisions of the arcs. Thesimplest algorithm for achieving arc consistencyrepeats the revisions until the domain of any

(0,0,1), (0,1,0),(1,0,0)

(0,0,1), (0,1,0),(1,0,0)

(0,0,1), (0,1,0),(1,0,0)

(0,0,1), (0,1,0),(1,0,0)

R21 & R33

R33 R22 & R33

R31

R11

v1

v2

v4

v3

(0,0,1), (0,1,0),(1,0,0)

(0,0,1), (0,1,0),(1,0,0)

(0,0,1), (0,1,0),(1,0,0)

(0,0,1), (0,1,0),(1,0,0)

r1v1

v2

v4

v3

0,1 0,1 0,1 0,1 0,1 0,1x1 x2 x3 x4 x5 x6

r1

r1

r1

r2

r2 r2

r2r3

r3 r3

r3

x1

x2

x3

Page 3: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

variable is changed. This algorithm is called AC-1and it suffers from the problem of non-necessaryrepetition of revisions. In particular, if a domain ofany variable is changed then only the arcs going tothis variable are affected by this reduction.Moreover the arc going from the variable thatcaused the domain reduction does not need to berevised again because it is not affected by thisdomain reduction. Figure 4 shows which arcsshould be re-revised after domain reduction.

Figure 4: Only some arcs (bold) need to be re-revised afterdomain reduction caused by another arc (dashed).

The idea of repeating only the necessary revisionswas included in the ancient Waltz algorithm forscene labelling [30]. This algorithm wasgeneralised to solve arbitrary CSP and it is calledAC-2. A more efficient version of this algorithmwhich keeps a single queue of arcs for re-revision iscalled AC-3 and it is probably the most widely usedconsistency algorithm.

Figure 5: AC-3 algorithm

AC-1 to AC-3 algorithms are described in [15], andtheir complexity is studied in [16]. AC-3 stillrepeats many constraint checks that can be avoidedby better bookkeeping. Therefore Mohr andHenderson [17] proposed AC-4 algorithm thatmaintains a support set for each value. In particular,for each value of the variable i there is a counterindicating how many supporters this value has inthe domain of the variable j, plus there is a structurekeeping the pairs (variable, value) which aresupported by the current value. By maintainingthese structures constraint checks can be fullyavoided during run of AC-4 algorithm.

Figure 6: Data structures used by AC-4

AC-4 is proved to have the optimal worst casecomplexity, unfortunately, in many cases itscomplexity is close to this worst case due tocomplexity of initialisation of the data structures(counters and support sets). Therefore Bessiere [4]proposed AC-6 algorithm that improves bothmemory consumption of AC-4 and average timecomplexity. Instead of keeping the completesupport sets and counters, AC-6 algorithmremembers only one supporter for each value. Ifthis supporter is lost by domain reduction thenanother supporter is looked for. Thus, complexityof the initialisation of AC-4 is spread over thepropagation phase of AC-6 algorithm and no largedata structures are necessary. AC-7 by Bessiere,Freuder, and Regin [9] is an extension of AC-6 thatuses symmetry of the constraint: if the value v1

supports another value v2 then v2 supports v1 aswell.

In the previous text we skipped AC-5 algorithmthat was proposed by Hentenryck, Deville, andTeng in [29]. AC-5 is a generic arc consistencyalgorithm that can be reduced both to AC-3 withgood average complexity or to AC-4 with the bestworst complexity. Moreover, this algorithm mayexploit semantic information during constraintrevision, in particular it brings better complexity iffunctional, anti-functional, or monotonicconstraints are used.

Arc consistency algorithms need to re-revise somearcs after domain reduction due to non-directionalcharacter of AC causing cycles in the constraintnetwork. If we order the variables in the constraintnetwork then we can keep consistent only the arcs(i,j) where i<j. This is called directional arcconsistency (DAC). Making the CSP directional arcconsistent is much more efficient than full AC, eacharc is revised exactly once, no re-revisions arenecessary if the arcs are explored in a clever order(arc (i,m) should be revised before any arc (j,n),where m>n). DAC is strictly weaker than AC and,in general, it is not possible to achieve AC bymaking DAC in both directions (if the constraintnetwork has a tree shape then AC can be achievedby two runs of DAC).

Path consistency. It is known that arc consistencydoes not remove all inconsistencies from theconstraint network meaning that even if the graph isAC then we still do not know if any solution exists.Therefore stronger consistency techniques wereproposed and studied. A natural extension of arcconsistency is path consistency (PC).

We say that a path (V1,…,Vn) is path consistent iffor every pair v1,vn of consistent values (i.e., thispair satisfies all binary constraints between V1 andVn) there exist values v2,…vn-1 such that all theconstraints Vi,Vi+1 are satisfied. Note, that thisdefinition says nothing about satisfaction of

procedure AC-3(G)Q ←← {(i,j) | (i,j)∈∈arcs(G), i≠≠j}while Q non empty doselect and delete (k,m) from Qif REVISE((k,m)) thenQ ←← Q ∪∪ {(i,k) | (i,k)∈∈arcs(G), i≠≠k, i≠≠m}

end ifend while

end AC-3

counter

2

1

1

support set

(i,a1),(i,a2)

(i,a1)

(i,a2),(i,a3)

i

a1

a2

a3

j

b1

b2

b3

Page 4: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

constraints between Vi and Vj for |i-j|>1. CSP ispath consistent if all paths are path consistent.Nevertheless, as Montanary showed in [18] it isenough to make paths of length two path consistentto make the CSP path consistent. Therefore pathconsistency algorithms work with paths of lengthtwo only and, like AC algorithms, they make thesepaths consistent by repeated revisions. Everyconstraint is represented extensionally using 0-1matrix and path revisions are performed usingmultiplication and conjunction of these matrices asFigure 7 shows.

Figure 7: Revision of path (A,B,C) where the initial domain forthe variables A,B,C is 1,…,3.

PC-1 repeatedly updates all paths until a domain ofany constraint is changed. Like AC-2 and AC-3, thePC-2 algorithm repeats revisions of only the pathsaffected by any previous revision and thus itsignificantly improves performance. Both PC-1 andPC-2 algorithms are described in [15] and theircomplexity is studied in [16]. Mohr and Hendersonattempt to apply the AC-4 principle to a pathconsistency algorithm and in [17] they proposed thePC-3 algorithm. Visibly, this algorithm is not soundbecause it can remove consistent values fromvariables' domains. In [14] Han and Lee proposed acorrection of this algorithm called PC-4. In [23]Singh proposes an extension of PC-4 called PC-5using the same principle as AC-6 has to AC-4 (onlyone support is computed and a new support islooked for when the current support is lost).

Even if path consistency is strictly stronger than arcconsistency, it is rarely used in practice. This isbecause PC suffers from several problems:

§ PC eliminates more inconsistencies then ACbut the performance/complexity ratio is muchworse than for AC,

§ PC requires an extensional representation ofconstraints and thus it has huge memoryconsumption even for small problems,

§ PC changes connectivity of the constraintnetwork by introducing derived constraints,and, thus, solving methods exploiting thenetwork structure are not applicable,

§ finally, PC still does not remove allinconsistencies.

Restricted path consistency. Because PCalgorithms suffer from many problems thatdisqualify them for practical applications, PierreBerlandier proposed a mixture of AC and PC calledrestricted path consistency (RPC) [3]. RPC keepsthe good features of AC, i.e., changing the domainsof variables (rather than the domains ofconstraints), and increases pruning power of AC bydoing PC when the value has only one support inthe constraint. Algorithm for RPC is based on AC-4algorithm that counts supports for individualvalues. As soon as a value has only one support inanother variable, PC is evoked for this pair ofvalues, i.e., a support for this pair is looked for inthe domain of other variables. If no such supportexists then we can remove the value from thedomain. RPC removes at least the same amount ofinconsistent values as AC and also some valuesbeyond. Thus, RPC is strictly stronger than any ACalgorithm. However, because PC is called onlyunder the condition of having a single support, RPCis weaker than full PC.

Figure 8: Restricted path consistency removes more inconsistentvalues than arc consistency.

k-consistency. Node, arc, and path consistency areinstances of a general consistency notion k-consistency. CSP is k-consistent if every consistent(k-1)-tuple can be extended to a consistent k-tuple.If the problem is j-consistent for every j≤k then weare speaking about strong k-consistency. Note thatstrong k-consistency implies k-consistency but notvice versa. Node consistency corresponds to 1-consistency, arc consistency to 2-consistency andpath consistency to 3-consistency. In fact, PCalgorithms include NC as well as AC so theyachieve strong path consistency (strong 3-consistency). There exist algorithms for achievingk-consistency for k>3 but they are even moreexpensive than PC and thus they are not used inpractice. Moreover, achieving k-consistency for theconstraint network with n vertices where k<n doesnot remove (in general) all inconsistent values. Onthe other side, it is known that if the constraintgraph has the width w and its is strongly k-consistent for k>w then a solution can be foundusing backtrack-free search [11]. Unfortunately, k-consistency for k≥3 changes the structure of theproblem so it is hard/impossible to keep a constantwidth of the graph when achieving k-consistency.So, only 2-consistency (i.e., arc consistency) can beused in practice with trees (graphs of width 1) toget a solution without backtracking.

V2

a

V1

b cd

e f

V3

removed by RPC

011 100 000 110 000001 & 010 * 010 * 111 = 001000 001 001 111 000

A=B B>C-2

B>1

ACA<C

Page 5: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

(i,j)-consistency. k-consistency can be furthergeneralised to (i,j)-consistency. A binary CSP is(i,j)-consistent if any consistent instantiation of idifferent variables can be extended to a consistentinstantiation including any j additional variables.Then k-consistency is equivalent to (k-1,1)-consistency. It is also possible to define strong (i,j)-consistency in an obvious way. The CSP is strongly(i,j)-consistent if it is (k,j)-consistent for every k≤i.Algorithms for achieving (i,j)-consistency needs tokeep tuples of i values so they are not practical fori≥2 due to memory consumption and changes in theconstraint network.

Inverse consistency. If increasing i in the (i,j)-consistency is not practical, then we can try toincrease j while keeping i=1. We get (1,k-1)-consistency which is called k-inverse consistency[11]. k-inverse consistency removes the values thatcannot be extended to a consistent instantiationincluding k-1 additional variables. This techniquedoes not change the constraint graph so it is spacecomplexity is linear. The worst-case timecomplexity is polynomial in k, so when k grows, theinverse consistency becomes quickly prohibitive.Note that there is no inverse consistency to arcconsistency (i.e., (1,1)-consistency) so the firstlevel removing more values than AC is path inverseconsistency (PIC). Growing k means morepruningful k-inverse consistency but its notpractical due to time complexity. A goodcompromise is to make sure that each value can beextended to a consistent instantiation of itsneighbourhood. This techniques proposed byFreuder and Elfe in [12] is called neighbourhoodinverse consistency. Unfortunately its exponentialworst-case time complexity cannot guaranteereasonable time efficiency.

Singleton consistency. In the previous paragraphswe illustrate several attempts to design an efficientfiltering algorithm that removes moreinconsistencies than AC. There exists a generictechnique that can improve pruning power ofarbitrary consistency algorithm, it is calledsingleton consistency [10,20]. Let A is some levelof consistency, e.g., arc consistency. Then CSP issingleton A-consistent if for any value v of anyvariable X the problem reduced using X=v is A-consistent. For example, we can define singletonarc consistency (SAC) or singleton restricted pathconsistency (SRPC). Even if singleton consistencycan be also expensive in cpu time, it is easy toimplement it provided that the underlying localconsistency algorithm is available.

Pruning power of some consistency techniques canbe compared easily using a generic notion of k-consistency (higher k implies more pruning power).However in case of inverse and singletonconsistencies the comparison is not so obvious. In

[10] these techniques were formally comparedconcerning their pruning power. The paper [20]concentrates on theoretical and empiricalcomparison of singleton consistencies. Figure 9summarise the results of these and other papersconcerning pruning power of basic consistencytechniques that are applicable to solving real-lifeproblems.

Figure 9: Comparison of pruning power of consistencytechniques. A→B means that A is strictly stronger than B (Aremoves more inconsistencies than B), dashed line meansincomparable techniques.

4 Non-binary and global constraintsIn Section 2 we mentioned that arbitrary CSP canbe translated to an equivalent binary CSP and thefiltering techniques surveyed in Section 3 weredesigned for binary CSP. However, conversion to abinary CSP is sometime/often impracticable andthus consistency notions and techniques are beingextended to non-binary constraints [5-8].

Generalised arc consistency. The notion of arcconsistency can be simply extended to non-binaryconstraints, then we are speaking about generalisedarc consistency. The constraint is generalised arcconsistent (GAC) if for any value of the variable inthe constraint there exist values for the othervariables in the constraint such that the tuplesatisfies the constraint.

AC-3 algorithm can be naturally extended to makethe constraint network generalised arc consistentand, in fact, this is the most widely used techniquein the current constraint satisfaction packages.Instead of revising the binary arc, this algorithmrevises the hyper-arcs. For example if the domainof the variable A is changed then the revision of theconstraint A+B=C is done by calling the followingtwo functions: C←A+B, B←C-A. Usually, insteadof remembering the hyper-arcs in the queue for re-revisions, this algorithm remembers the variablesthat domain has been changed. Then, the algorithmcalls the revision procedures connected to thesevariables. This approach gives the algorithmenough flexibility necessary for integration of userdefined filtering algorithms and, therefore, it is themost common algorithm provided by the constraintsatisfaction packages.

SRPC SAC ACRPCPIC

NIC

Strong PC

Page 6: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

GAC-schema. Arc consistency algorithmspresented in Section 3 were designed for binaryconstraints. In [5] a new schema for generalised arcconsistency were proposed based on AC-7algorithm. In [8], an instantiation of this schemawas proposed to achieve arc consistency on globalconstraints.

Global constraints. The disadvantage ofgeneralised arc consistency algorithms isdecreasing efficiency with growing cardinality ofthe constraint. As shown in [21], special filteringalgorithms can be designed for particularconstraints that achieve the same level ofconsistency but are more time and space efficientthanks to exploiting semantic information about theconstraint. Such special constraints are usuallycalled global constraints. They can be oftendecomposed to simpler (binary) constraints [13,18]but then the same consistency technique, say AC,has lower pruning power and therefore suchdecomposition often does not pay-off. Severalgroups of global constraints were proposedmotivated by real-life problems [2].

5 Propagation in practiceAfter surveying the basic filtering techniques usedto reduce domains of binary and non-binaryconstraints, let us now describe some less obvioustechniques how the constraint propagation can beimproved and how the filtering techniques shouldbe applied to solve real-life problems. Thediscussed techniques are derived from observationsof the author and others so they have more or lessexperimental nature.

Disjunction. Appearance of the disjunctiveconstraint in the problem formulation usuallycauses problems because of weak propagationthrough such constraint. Let us illustrate it with asimple example. Assume that variable x has adomain -10,…,10 and there is a disjunctiveconstraint (x≤-5 ∨ x≥5). One may assume(wrongly) that after posting this constraint, thedomain of the variable x is reduced to (-10,…,-5) ∪(5,…,10). Unfortunately, in most constraint systemsthis is not true and the domain of x stay -10,…,10.This is because propagation through particularconstraint in the disjunction is activated only whenthe other constraints are violated. For example, ifthe domain of x is reduced to say -10,…,3 then x≥5is not true so the other constraint x≤-5 is activatedand the domain of x is reduced further to -10,…, -5.In this clear example, there is a simple solution toincrease propagation: instead of the disjunctiveconstraint one may use the domain constraintx in (inf..-5)\/(5..sup). However, in a more complexdisjunction such reformulation may be morecomplicated or even impossible. Then the solutioncould be to use a more expensive constructive

disjunction (the domain of the variable is reducedto the union of domains after propagation throughthe individual constraints in the disjunction) or todesign an ad-hoc propagation algorithm.

Disjunction in CLP. When constraint logicprogramming (CLP) is used as an underlyingplatform for constraint solving then problems withdisjunction become even harder. Logicprogramming provides alternative clauses to modeldisjunction and many CLP users apply thisapproach when modelling problems withconstraints. For example the disjunctive constraintfrom the previous paragraph is modelled using thefollowing CLP code:

disj(X):-X#=<-5.disj(X):-X#>=5.

This means that a constraint X≤-5 is posted whendisj(X) is called and if we find later that this is notgood then the alternative constraint X≥5 is used.However, the only way how to install the constraintX≥5 is upon backtracking so everything that hasbeen done since the first call to disj(X) is lost. Thisunwanted behaviour of CLP when definingdisjunctive constraint using alternative clauses wasfirst observed in [28] where a solution using thecardinality operator has been proposed. In [26] theidea of cardinality operator is further extended.Nevertheless, note that cardinality operator stillsuffers from the problem with non-constructivedisjunction described in the previous paragraph.

Singleton consistency. As mentioned in Section 3,singleton consistency is a very powerful filteringtechnique close in pruning power to pathconsistency but resistant from path consistencyproblems. Unfortunately like other more powerfulconsistency techniques, achieving singletonconsistency is not cheap in terms of time.Therefore, it is not practical to maintain fullsingleton consistency during labelling. On the otherhand, implementation of singleton arc consistencyalgorithm is almost for free, it is a combination oflabelling, achieving arc consistency, and tablingvariables' domains. Note also that opposite to manyother consistency techniques, the implementation ofSAC does not require changes inside the constraintsatisfaction engine but it can be done at a meta-level.

We see several ways how singleton consistency canbe applied to improve domain filtering. First, it ispossible to make the constraint satisfaction problemsingleton consistent just once before labelling. Thisreduces domains more than simple AC whilekeeping reasonable time complexity. If achievingfull SAC is too expensive (and this could be prettyoften in large-scale real-life problems) then it is stillpossible to use SAC in a limited way. In particular,it is possible to apply SAC to selected variables that

Page 7: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

somehow determine the solution space. Reducingsome domains using SAC can then be propagatedto other variables using standard AC. Note that thislimited SAC can be applied within labelling as wellto achieve a weaker form of maintaining singletonconsistency. Maintaining limited singletonconsistency can also be used during prototyping aconstraint model. It is much easier to implementsingleton consistency then to design a specialpropagation algorithm (global constraint). Thus,singleton consistency (SC) can be used to test ifapplying stronger consistency over a particular setof variables pays off. If the answer is yes then it ispossible to design a special ad-hoc filteringalgorithm with similar pruning power as SC butmore time efficient than SC.

Redundant constraints. Usually, when the userformulates a problem, only the necessaryconstraints are included in the model. Redundantconstraints, i.e., the constraints that can be derivedfrom other constraints are often avoided. This isbecause redundant constraints do not contribute tothe solution set (their presence in the model doesnot shrink the solution set), and moreover, theyincrease overhead. On the other side, addingredundant constraints may further reduce domainsand, consequently, speed up search. Let us illustrateimproved propagation with redundant constraintsusing a simple CSP. Assume there are fourvariables x1,x2,x3,x4 with domains 0,…,5, twovariables y1,y2 with domains 3,…,8 and constraintsx1+x2=y1, x3+x4=y2, x1+x2+x3+x4=z. Visible thedomain for z should be 6,…,16 but the propagationinfers the domain 0,…, 25. If a redundant constrainty1+y2=z is added then we get the expected domainfor z.

Dual models. In Section 2 we discussed a dualencoding when converting a non-binary CSP to abinary CSP. In a real-life problem there alsotypically exist two dual encodings modelling thesame problem. In these encodings the constraintsare swapped for the variables and vice versa. Let usillustrate dual models using a well-known n-queensproblem, where the task is to place n queens onto an×n chessboard in such a way that the queens arenot in conflict. One may choose rows as variablesand the constraints describe consistent columns forthe queens. Or it is possible to use columns asvariables and the constraints describe thecompatible rows. Both encodings are fullyinterchangeable and typically only one of then ischosen to model the problem. However, if bothmodels are used in parallel, we can achieve betterpruning. Naturally, there must be specialconstraints that connect the variables of bothmodels, e.g. in case of n-queens the followingconstraint can be used: row(i)=j ⇔ column(j)=i.Using both primal and dual model can significantlyimprove domain reduction, e.g. we get a solution

five times faster for 200 queens when primal anddual encoding was used together. However, onemust be very careful about combining bothencodings because adding more (redundant)constraints increases overheads of propagation.Sometime this overhead wipes the advantage ofbetter domain filtering and sometimes there is noadditional pruning when a dual model is usedtogether with the primal one.

Symmetries. Removing inconsistent values fromthe variables' domains is the main task of constraintpropagation. Sometimes, we can improve thispropagation by removing symmetrical solutions,i.e., the solutions that can be achieved from anothersolution by swapping the values of some variables.See Figure 10 for two symmetries in n-queensproblem (for simplicity reasons we do not discussrotation in the n-queens problem).

Figure 10: Horizontal (left) and vertical (right) symmetricalsolution to the n-queens problem achieved by mirroring thechessboard over the horizontal and vertical axes.

Symmetry divides the set of possible assignmentsinto equivalence classes. If the search algorithmproves that there is no solution in some class thenwe do not need to explore the equivalent classesbecause there is no solution as well. Thus, we canexploit symmetry of the problem to improvedomain pruning. Assume that we found that thequeen in the first column could not be placed to thefirst row. Using a horizontal symmetry we candeduce that this queen cannot be placed to the lastrow as well. This symmetry can be encoded usingthe following constraint row(1)≤n/2, i.e., the queenin the first column must be placed in the top half ofthe board. Note that this constraint removes thehorizontal symmetry. The vertical symmetry can beremoved by using a constraint row(1)<row(n).Notice also that information about forbidden firstrow for the first queen implies that the last row isforbidden for the last queen too. This combinedsymmetry can be removed by the constraintrow(n)≤n-row(1).

Removing symmetries can significantly improvedomain reduction especially in highly symmetricproblems. Symmetries can also be used to get moresolutions from a single solution without wastingtime to find them via search. Some approaches toreducing the symmetry, namely remodelling theproblem, adding constraints, and adding constraintsduring search, are discussed in [25].

Page 8: Theory and Practice of Constraint Propagationktiml.mff.cuni.cz/~bartak/ESSLLI2002/files/cpdc2001.pdfTheory and Practice of Constraint Propagation Roman Barták* Charles University,

6 ConclusionsThe paper is focused to practitioners usingconstraint programming to solve various problemsas well as to theoreticians looking for a brief surveyof consistency techniques that can be used to solvereal-life problems. We also discuss some modellingissues leading to improve propagation and thus tofind a solution faster.

7 References[1] Bacchus F. and van Beek, P.: On the Conversion between

Non-Binary and Binary Constraint Satisfaction Problems,in Proceedings of AAAI-98, pp 311-319, 1998.

[2] Beldiceanu N. and Contejean E.: Introducing GlobalConstraints in CHIP, in Mathematical ComputerModelling 20 no. 12, pp. 97-123, 1994.

[3] P. Berlandier. Improving Domain Filtering usingRestricted Path Consistency, in Proceedings of the IEEECAIA-95, Los Angeles CA, 1995.

[4] Bessiere Ch., Arc-consistency and arc-consistency again,in Artificial Intelligence 65, pp. 179-190, 1994.

[5] Bessiere Ch., Régin J.-Ch.: Arc consistency for generalconstraint networks: preliminary results, in Proceddingsof IJCAI97, pp. 397-404, 1997.

[6] Bessiere Ch.: Non-binary constraints, in Proceedings ofCP99, pp.24-27, Alexandria, USA, 1999.

[7] Bessiere Ch., Meseguer P., Freuder E., Larrosa J.: OnForward Checking for Non-binary ConstraintSatisfaction, in Proceedings of CP99, pp. 88-102,Alexandria, USA, 1999.

[8] Bessiere Ch. and Régin J.-Ch.: Enforcing arc consistencyon global constraints by solving subproblems on the fly,in Proceedings of CP99, pp. 103-117, Alexandria, USA,1999.

[9] Bessiere Ch., Freuder E., Régin J.-Ch.: Using ConstraintMetaknowledge to Reduce Arc Consistency Computation,in Artificial Intelligence 107, pp. 125-148, 1999.

[10] Debruyne R. and Bessiere Ch.: Some PracticableFiltering Techniques for the Constraint SatiscationProblems, in Proceedings of IJCAI97, pp. 412-417, 1997.

[11] Freuder E.: A sufficient condition for backtrack-boundedsearch, in Journal of the ACM 32(4), pp. 755-761, 1985.

[12] Freuder E. and Elfe Ch.: Neighborhood InverseConsistency Preprocessing, in Proceedings of the AAAINational Conference, pp. 202-208, 1996.

[13] Gent I., Stergiou K., Walsh T.: DecomposableConstraints, in Artificial Intelligence 123 (1-2), pp. 133-156, 2000.

[14] Han C. and Lee C.: Comments on Mohr and Henderson'spath consistency algorithm, in Artificial Intelligence 36,pp. 125-130, 1988.

[15] Mackworth, A.K.: Consistency in Networks of Relations,in: Artificial Intelligence 8(1), pp. 99-118, 1977.

[16] Mackworth A.K., Freuder E.C.: The complexity of somepolynomial network consistency algorithms for constraintsatisfaction problems, in Artificial Intelligence 25, pp. 65-74, 1985.

[17] Mohr R. and Henderson T.C.: Arc and path consistencyrevised, in Artificial Intelligence 28, pp. 225-233, 1986.

[18] Montanary, U.: Networks of constraints: fundamentalproperties and applications to picture processing, in:Information Sciences 7:, pp. 95-132, 1974.

[19] Perlin M.: Arc consistency for factorable relations, inArtificial Intelligence 53, pp. 329-342, 1992.

[20] Prosser P., Stergiou K., Walsh T.: SingletonConsistencies, in Proceedings of CP2000, pp. 353-368,Singapore, 2000.

[21] Régin, J.-Ch.: A filtering algorithm for constraints ofdifference in CSPs, Research Report LIRMM 93-068,Université Montepellier, France, 1993.

[22] Rossi F. and Dhar V.: On the Equivalence of ConstraintSatisfaction Problems, in Proceedings of ECAI90, pp.550-556, Stockholm, Sweden 1990.

[23] Singh M.: Path Consistency Revised, in Proceedings ofIEEE International Conference on Tools with ArtificialIntelligence, pp. 318-325, 1995.

[24] Smith B., Stergiou K., Walsh T.: Using auxiliaryvariables and implied constraints to model non-binaryproblems, in Proceedings of AAAI2000, 2000.

[25] Smith B.: Reducing Symmetry in a Combinatorial DesignProblem, in Proceedings of CP-AI-OR2001, pp. 351-359,Wye College, UK, 2001.

[26] Steggiou K., Walsh T.: Encodings of Non-BinaryConstraint Satisfaction Problems, in Proceedings ofAAAI-99, 1999.

[27] Van Der Linden A.S.J.: Dynamic Meta-Constraints: AnApproach to Dealing with Non-Standard ConstraintSatisfaction Problems, PhD Thesis, Oxford BrookesUniversity, 2000.

[28] Van Hentenryck P. Deville Y.: The Cardinality Operator:A new Logical Connective for Constraint LogicProgramming, in Proceedings of ICLP91, pp. 745-759,1991.

[29] Van Hentenryck P., Deville Y., Teng C.M.: A genericarc-consistency algorithm and its specialisation, inArtificial Intelligence 57, pp. 291-321, 1992.

[30] Waltz, D.L.: Understanding line drawings of scenes withshadows, in: Psychology of Computer Vision, McGraw-Hill, New York, 1975