as a PDF

advertisement
Constraint Manipulation using Rewrite Rules and
Strategies
Carlos Castro
INRIA Lorraine & CRIN
615, rue du Jardin Botanique, BP 101,
54602 Villers-les-Nancy Cedex, France
e-mail: Carlos.Castro@loria.fr
Abstract
1 Introduction
In the last twenty years many work has been
done on solving Constraint Satisfaction Problems
(CSP). Several languages and libraries are now
available to deal with CSP and they have been
successfully applied for solving real life problems.
These tools are mainly based on procedural or
Prolog-like languages. We are interested in constraint manipulation using rule-based algorithms
because of the explicit distinction made in this approach between deduction rules and control. We
associate actions with rewrite rules and control
with strategies that establish the order of application of the inferences. This framework allows
us to describe constraint handling in a very abstract way, prototype new heuristics almost only
modifying the choice of rules, prove termination
in a easier way and possibly partly automated,
and combine constraint solving with other computational systems. Prototype new heuristics and
prove termination are not obvious tasks in black
box like algorithms. Our rst goal is to improve
our understanding of the algorithms developed for
solving CSP once, they are expressed as rewrite
rules coordinated by strategies, and then to be
able to propose new ones. Extending the domain
of application of Rewriting Logic to CSP is another motivation for our work. This leads the way
to the design of a formalism that allows the application of the knowledge already developed in
the domain of Automated Deduction, to the constraint solving process. To verify our approach we
have implemented a prototype which is currently
executable in the system ELAN [11], an interpreter
of computational systems.
This paper is organised as follows: Section 2
We are interested in constraint manipulation using rule-based algorithms because of the explicit
distinction made in this approach between deduction rules and control. We associate actions with
rewrite rules and control with strategies that establish the order of application of the inferences.
This framework allows us to describe constraint
handling in a very abstract way, prototype new
heuristics almost by modifying only the choice of
rules, prove termination in an easier and possibly partially automated way, and combine constraint solving with other computational systems.
Our rst goal is to improve our understanding of
the algorithms developed for handling Constraint
Satisfaction Problems, once they are expressed as
rewrite rules coordinated by strategies, and then
to be able to propose new ones. Extending the
domain of application of Rewriting Logic to constraint solving is another motivation for our work.
In this paper, we formalise constraint solving as an
inference process and we present a new technique
for handling disjunctive constraints. We hope that
this work leads the way to the design of a formalism that allows the application of the knowledge
already developed in the domain of Automated
Deduction, to the constraint solving process. To
verify our approach we have implemented a prototype which is currently executable in the system
ELAN, an interpreter of computational systems.
Keywords:
Constraint Satisfaction Problems,
Rewriting Logic, Computational Systems.
1
contains some denitions and an overview about
CSP solving, in section 3 we briey present a
computational system for CSP solving, section 4
presents a new technique to deal with CSPs involving disjunctive constraints and section 5 concludes the paper, presents the work we are currently developing and further ideas.
variables, by e the number of binary constraints
and by a the number of elements in the domain
D (a = C ard(D)).
Typical tasks dened in connection with CSP
are to determine whether a solution exists, and to
nd one or all the solutions. In this section we
present three categories of techniques used in processing CSP: Searching Techniques, Problem Reduction, and Hybrid Techniques. Kumar's work
[12] is an excellent survey on this topic.
2 CSP
Formally, an elementary constraint c? is an atomic
formula built on a signature = (F ; P ), where
F is a set of ranked function symbols and P a
set of ranked predicate symbols, and a denumerable set X of variable symbols 1 . Elementary constraints are combined with usual rst-order connectives. We denote the set of constraints built
from and X by C (; X ). Given a structure
D = (D; I ), where I is an interpretation function and D the domain of this interpretation, a
h; X ; Di-CSP is any set C = (c?1 ^ : : : ^ c?n) such
that c?i 2 C (; X ) 8i = 1; : : :; n. A solution of c?
is a mapping from X to D that associates to each
variable x 2 X an element in D such that c? is
satisable in D. The solution set of c? is given by:
Searching Techniques in CSP Searching
consists of techniques for systematic exploration
of the space of all solutions. The simplest algorithm generate-and-test, also called trial-anderror search, is based on the idea of testing every possible combination of values to obtain a solution of a CSP. Intending to avoid the obvious
combinatorial explosion of generate-and-test the
basic algorithm commonly used for solving CSPs
is the simple backtracking search algorithm, also
called standard backtracking or depth-rst search
with chronological backtracking [4]. The time complexity of backtracking is O(an e), i.e., the time
taken to nd a solution tends to be exponential
in the number of variables [14]. In order to avoid
the exploration of subtrees of the backtrack search
SolD (c? ) = f 2 XD j(c?) = Tg:
tree that dier only in inessential features (thrashA solution of C is a mapping such that all con- ing,) such as the assignments to variables irrelestraints c?i 2 C are satisable in D. The solution vant to the failure of the subtrees, the notion of
set of C is given by:
problem reduction has been developed.
Problem Reduction in CSP Problem reduc-
SolD (C ) = f 2 XD j(c?i ) = T 8i = 1; : : :; ng:
tion techniques transform a CSP to an equivalent
problem by reducing the values that the variables
can take. Given the CSPs P and P 0 whose solution set are Sol(P ) and Sol(P 0 ), respectively, we
say that they are equivalent if Sol(P ) = Sol(P 0 ):
A CSP P is reduced to P 0 if P and P 0 are equivalent, the set Dx 0 associated to each membership constraint x 2? Dx 0 in P 0 is a subset of the
set Dx associated to each membership constraint
x 2? Dx in P , and the set of constraints C 0 in P 0
is more restrictive than, or as restrictive as, the
set of constraints C in P . Problem reduction is
often refered to as consistency maintenance [17].
Consistency concepts have been dened in order
to eliminate combinations of values which could
not appear together in any set of values satisfying
1 For clarity, constraints are syntactically distinguished the set of constraints and obtaining in this way
from formulae by a question mark exponent on their pred- a reduced problem. Mackworth [13] establishes
icate symbols.
three levels of consistency: node, arc and pathGiven a variable x 2 X and a non-empty set
Dx D, the membership constraint of x is a relation given by x 2? Dx : We use these membership constraints to make explicit the domain reduction process during the constraint solving. In
practice, the sets Dx have to be set up to D at
the beginning of the constraint solving process,
and constraint propagation will eventually reduce
them. We consider CSPs in which the carrier of
the structure is a nite set and the constraints are
only unary or binary. This class of CSP is known
as Binary Constraint Satisfaction Problems. To
represent Binary CSPs graphs are generally used,
that is why a CSP is also called a Constraint Network. In this work, we denote by n the number of
2
consistency. These names come from the fact that
general graphs have been used to represent Binary
CSP. A general notion of k-consistency was introduced in [9], where 1-consistency, 2-consistency
and 3-consistency correspond to node, arc and
path-consistency, respectively. The varying forms
of consistency algorithms can be seen as approximation algorithms, in that they impose necessary
but not always sucient conditions for the existence of a solution on a CSP. We now give the
standard denitions of node and arc-consistency
for a binary network of constraints 2 .
[8] use complex data structures to keep the optimal worst-case time complexity of AC-4 while
working out the drawback of space complexity of
AC-4. As our aim in this work is only to introduce a new framework to model CSP, we use AC-3
because we need a very simple data structure to
implement it.
Hybrid Techniques As backtracking suers
from thrashing and consistency algorithms can
only eliminate local inconsistencies, hybrid techniques have been developed. In this way we obtain a complete algorithm that can solve all problems and where thrashing can be reduced. Hybrid techniques integrate constraint propagation
algorithms into backtracking in the following way:
whenever a variable is instantiated, a new CSP
is created; then a constraint propagation algorithm is applied to remove local inconsistencies
of these new CSPs [23]. Embedding consistency
techniques inside backtracking algorithms is called
Hybrid Techniques. A lot of algorithms that essentially t the previous format have been proposed. Forward Checking, Partial Lookahead, Full
Lookahead, and Really Full Lookahead, for example, primarily dier in the degrees of arc consistency performed at the nodes of the search tree.
Denition 1 (Node consistency) Given a
variable x 2 X and a unary constraint c? (x) 2 C ,
the node associated to x is consistent if
8 2 XD : 2 SolD (x 2? Dx ) ) 2 SolD (c? (x)):
A network of constraints is node-consistent if all
its nodes are consistent.
Verication of node consistency is obvious, the
algorithm NC-1 proposed by Mackworth [13] carries out this task and its time complexity is O(an)
[14].
Denition 2 (Arc consistency) Given the
variables xi ; xj 2 X and the constraints
c?i (xi ); c?j (xj ); c?k (xi; xj ) 2 C , the arc associ-
3 A Computational System
for Solving CSP
ated to c?k (xi ; xj ) is consistent if
8 2 XD 90 2 XD : 2 SolD (xi 2? Dx ^ c?i (xi ))
i
) 0 2 SolD (xj 2? Dx
j
The idea of solving constraint systems using com-
systems was rstly proposed by Kirch^ c?j (xj ) ^ c?k ((xi); xj )): putational
ner, Kirchner and Vittek in [10] where they de-
A network of constraints is arc-consistent if all ne the concept of computational systems and
describe how a constraint solver for symbolic conits arcs are consistent.
straints can be viewed as a computational system aimed at computing solved forms for a class
of considered formulas called constraints. They
point out some advantages of describing constraint solving processes as computational systems over constraint solving systems where solvers
are encapsulated in black boxes, such as reaching
solved forms more eciently with smart choices
of rules, easier termination proofs and possibly
partly automated, description of constraint handling in a very abstract way, and easy combination of constraint solving with other computa2 In this work, we do not use the concept of path- tional systems. Following [10], a computational
consistency because it has been proved that algorithms for system is given by a signature providing the synachieving path-consistency do not pay-o their cost.
tax, a set of conditional rewrite rules describing
Several algorithms have been proposed for
achieving arc consistency. In [13], Mackworth
proposes AC-3 whose time complexity is O(a3 e)
[14]. In [16] Mohr and Henderson propose the algorithm AC-4 whose worst-case time complexity
is O(ea2 ) and they prove its optimality in terms
of time. But, in problems with many solutions,
where constraints are large and arc-consistency
removes few values, AC-3 runs often faster than
AC-4 despite its non-optimal time complexity [21].
Algorithms like AC-6 [1], AC-6++ [2] and AC-7
3
the deduction mechanism, and a strategy to guide
application of rewrite rules. Formally, this is the
combination of a rewrite theory in rewriting logic
[15], together with a notion of strategy to eciently compute with given rewrite rules. Computation is exactly application of rewrite rules on
a term and strategies describe the intented set of
computations, or equivalently in rewriting logic, a
subset of proofs terms.
of consistency we are imposing on the constraint
set. So, a CSP P in unary solved form is a system in basic form whose set of constraints is node
consistent, and a CSP P in binary solved form is
a system in basic form whose set of constraints is
arc consistent.
Denition 4 (Solved form) A solved form for
a CSP P is a conjunction of formulae in basic
form equivalent to P and such that all basic assignments satisfy all constraints. A basic assignment of a CSP P in solved form is called solution.
3.1 Solved Forms
Term rewriting repeatedly transforms a term into
an equivalent one, using a set of rewrite rules, until
a normal form is eventually obtained. The solved 3.2 Rewrite Rules
form we use is dened with the notion of basic In [5] we propose ConstraintSolving a set of
rewrite rules for solving CSP, which is presented
form.
in gure 1.
Denition 3 (Basic form) A basic form for a We use a constant F to denote a unsatisCSP P is any conjunction of formulae of the form able CSP. The rule Node-Consistency, where
RD(x 2? Dx ; c?(x)) stands for the set Dx0 =
^
^
^ ?
fv 2 Dx j c?(v)g, veries node consistency
(xi 2 Dxi ) ^ (xj =? vj ) ^ (c?k )
and it is based on NC-1 algorithm. The rule
j 2J
i2I
k2K
Arc-Consistency, where RD(x1 2? Dx1 ; x2 2?
Dx2 ; c?(x1 ; x2)) stands for the set Dx0 1 = fv 2
equivalent to P such that
Dx1 j (9w 2 Dx2 ) c? (v; w)g, veries arc consistency and it is based on AC-3 algorithm. Rule
8i1 ; i2 2 I; i1 6= i2 ) xi 1 6= xi 2
Instantiation corresponds to a variable assign 8i 2 I; Dxi 6= ;
ment. Elimination expresses the fact that once
a variable has been instantiated, we can propagate
8j1; j2 2 J; j1 6= j2 ) xj 1 6= xj 2
its value through all constraints where the variable
is involved in. C fx 7! vg denotes the conjunction
8i 2 I 8j 2 J xi 6= xj
of constraints obtained from C by replacing all
8k 2 K 9i 2 I 9j 2 J; xk = xi _ xk = xj occurrences of the variable x by the value v. The
rule Falsity expresses the obvious fact of unsatisThe constraints in the rst, second, and third ability.
The rule Generate expresses the simple
conjunction are called membership, equality, and fact of branching
to carry out exhaustive search.
functional constraints, respectively. For each variable we have associated a membership constraint Lemma 1 The set of rules ConstraintSolving
or an equality constraint, the set associated to is correct and complete.
each variable in the membership constraints must
not be empty, and for each variable appearing Proof: See [5].
in the functional constraints there must be associated a membership constraint or an equality Theorem 1 Starting with a CSP P and applying
constraint. Variables which are only involved in repeatedly the rules in ConstraintSolving until
equality constraints are called solved variables and no rule applies anymore results in F i P has no
the others non-solved variables.
solution or else it results in a solved form of P .
A CSP P in basic form can be associated with a
basic assignment obtained by assigning each vari- Proof: See [5].
able in the equality constraints to the associated
value v and each variable x in the membership ConstraintSolving was designed to deal with
constraints to any value in the set Dx . In this way elementary constraints. In order to combine them
we can dene several forms depending on the level with rst-order connectives we add a new rule
4
[Node ? Consistency] x 2? Dx ^ c? (x) ^ C
) x 2? RD(x 2? Dx ; c?(x)) ^ C
[Arc ? Consistency] x1 2? Dx1 ^ x2 2? Dx2 ^ c?(x1 ; x2) ^ C
) x1 2? RD(x1 2? Dx1 ; x2 2? Dx2 ; c?(x1; x2)) ^
x2 2? Dx2 ^ c? (x1; x2) ^ C
if RD(x1 2? Dx1 ; x2 2? Dx2 ; c?(x1; x2)) 6= Dx1
[Instantiation]
x 2? Dx ^ C
) x =? (x) ^ C
if fg = SolD (x 2? Dx )
[Elimination]
x =? v ^ C
) x =? v ^ C fx 7! vg
if x 2 V ar(C )
[Falsity]
x 2? ; ^ C
[Generate]
) F
x 2? Dx ^ C
) x =? (x) ^ C or x 2? Dx n(x) ^ C
if 2 SolD (x 2? Dx )
Figure 1: ConstraintSolving: Rewrite rules for solving Binary CSP
[CreateChoicePoint] (c?1 _ c?2) ^ C
) c?1 ^ C or c?2 ^ C
Figure 2: CreateChoicePoint: Rewrite rule for creating a choice point
CreateChoicePoint that creates a choice point, 3.3 Strategies
i.e., posts the disjuncts of a disjunctive constraint. As we have mention there are several heuristics
This rule is presented in gure 2.
to search for a solution in CSP, starting from the
brute force generate and test algorithm until elaborated versions of backtracking. The expressive
power of computational systems allows to express
these dierent heuristics through the notion of
As all rst-order connectives can de expressed strategy. In this way, for example, a unary solved
using conjunctions and disjunctions we can now form can be obtained by applying
deal with all of them, we just have to put the
j
set of constraints in a conjunctive normal form. [Node-Consistency j CreateChoicePoint
Falsity
]
The right hand side of rule CreateChoicePoint
is equivalent to (c?1 or c?2) ^ C . This expression A binary solved form can be obtained by applyis equivalent to (c?1 _ c?2 ) ^ C , the left hand side of ing
the rule, so rule CreateChoicePoint is correct
j CreateChoicePoint j
and complete. As CreateChoicePoint creates [Arc-Consistency
Falsity
]
a new subproblem for each disjunct involved in a
disjunctive constraint, the solution for the origi- And a solved form for a set of elementary connal problem is in the union of the solution to each straints can be obtained using the strategy
subproblem, and as nally each subproblem is a
[[Generate; Elimination] j Falsity]
conjunction of elementary constraints theorem 1
is still valid when we consider together the set of which implements exhaustive search 3.
rules ConstraintSolving and the rule Create- 3 The symbol means applying a given rule zero or N
times over the constraint system.
ChoicePoint.
5
We can integrate constraint propagation and
search in order to get a solved form more eciently than the force brute approach. Let us dene the following strategies:
NodeC :: [Node-Consistency;
[Instantiation; EliminationjFalsity]]
ArcC :: [Arc-Consistency;
[Instantiation; EliminationjFalsity]]
Considering only elementary constraints, the
strategy
[NodeC j ArcC] ;
[Generate; EliminationjFalsity]
implements a preprocessing which veries node
and arc consistency and then carries out an exhaustive search in the reduced problem. Considering disjunctive constraints, the strategy
[NodeC j ArcC] ; [CreateChoicePoint;
[NodeC j ArcC] ; Generate; Elimination;
NodeC]
implements an heuristic which, once node and
arc consistency have been veried, carries out a
loop which rstly creates a choice point, then veries node and arc consistency, then carries out an
enumeration step, and nally veries node consistency. This last one is a particular version of Forward Checking an heuristic widely used in CSP.
all constraints in store are k-consistent and all
the variables in the membership constraints have
associated a non-empty set.
ELAN is a system for prototyping nondeterministic computations thanks to rules and
strategies. Strategies is one of the main originalities of ELAN compared to other algebraic specication languages based on rewriting. A strategy is a way to describe which computations the
user is interested in, and species where a given
rule should be applied in the term to be reduced. We describe informally here how ELAN
deals with rewrite rules and strategies and we
present an overview of our prototype. A full description of the language can be found in [3]. All
details about the prototype can be obtained at
http://www.loria.fr/~castro/CSP/csp.html.
3.4.1 Rewrite Rules
Rules are labelled conditional rewrite rules with
local variable assignments
[`] : l ) r if v where y := [S ]u
` is the rule label, l and r the respective left and
right-hand sides, v the condition and y := [S ]u a
local assignment, assigning to the local variable y
the result of the strategy S applied to the term u.
For applying such a rule on a term t, say at top
position, rst l is matched against t. Then the expressions in where and if parts, instantiated with
the matching substitution, are evaluated in order.
When there is no failure, this usually instantiates
the local variables (such as y) in where expressions, and this extends the matching substitution.
When every condition is satised, the replacement
by the instantiated left-hand side is performed.
As an example, gure 3 presents the implementation of Node-Consistency using ELAN.
This rule establishes that if the rst constraint,
c, in the list of constraints has arity equals to
1, the operator Verify NC will be applied, this
result will be assigned to Q and nally the left
hand side will be rewritten to Q. The rule Node
Consistency corresponds to the high level of the
verication of local consistency following the idea
of algorithm NC-1. The actual verication of values is carried out by the operator Verify NC which
is presented in a general way in gure 4.
The operator Verify NC manipulates the data
structure using two kinds of basic operators.
3.4 Implementation
We have implemented a prototype which is currently executable in the system ELAN [11], an interpreter of computational systems4 . We use a 4tuple CSP[lmc,lec,C,store] to represent a CSP,
where lmc is a list with the membership constraints, lec is a list with the equality constraints,
C is a list with the set of constraints to solve
and store is a list with the constraints already
veried. Our implementation for achieving local
consistency is mainly based on algorithm AC-3,
the constraints in C are veried and stored in the
store, once a variable's domain is modied we extract all constraints in the store where the variable is involved in and add them to C. So, a kconsistent CSP is obtained once the list C is empty,
4 ELAN is available via anonymous ftp at ftp.loria.fr
in the directory /pub/loria/protheo/softwares/Elan.
Further information can be obtained at
http://www.loria.fr/equipe/protheo.html
6
csp
c : formula ; lmc , l e c ,C , st ore : l i s t [ formula ] ; Q: csp ;
rules for
global
[ NodeConsistency ]
end
CSP [ lmc , l e c , c . C, s tor e ]
=>
Q
i f ArityOfC onstr aint ( c ) == 1
where
Q := ( ) Verify ? NC (CSP [ lmc , l e c , c . C, s to re ] )
Figure 3: Rule Node-Consistency: Verication of Node-Consistency
tional matching and second to the where assignment, since it may itself return several possible
assignments for variables, due to the use of strategies. When a rewrite rule or a strategy returns an
empty set of terms, we say that it fails. Thus
the language provides a way to handle this nondeterminism. This is done using three basic strategy operators: dc, standing for dont care choose,
dk, standing for dont know choose, and rst. For
a rewrite rule [`] : l ) r the strategy dc(`) returns at most one result which is undeterministically taken among the possible results of the application of the rule. rst is a 'sequential version' of dont care choose, which takes always the
rst, in textual order, successful branch. On the
contrary, if the ` rule is applied using the dk(`)
strategy, then all possible results are computed
and returned by the strategy. The implementation handles these several results by an appropriate back-chaining operation. This is extended to
the application of several rules: the dk strategy
results in the application of all sub-strategies and
yields the concatenation of all results; the application of the dc strategy returns the set of results
of one (the rst) non-failing rule application. If all
sub-strategies fail, then it fails too, i.e. it yields
the empty set. The strategy constants id and fail
respectively represent identity and failure.
The current implementation of our system
includes strategies that implement exhaustive
search, local consistency and hybrid techniques.
As a basic example, gure 6 presents the implementation of local consistency for a set of elementary constraints.
More interesting heuristics as Forward Check3.4.2 Strategies
ing, and Full Lookahead can be easily impleApplication of a rewrite rule in ELAN yields, in mented using the powerful of strategies in ELAN.
general, several results. This is rst due to equa- Figure 7 presents a simple version of Forward
The basic operator GetVarOfFormule(c), returns the list of variables involved in the constraint c, GetVarInHead(x,l,nil) returns a list
of constraints where the rst element corresponds
to the membership constraint associated to
x, and GetConstraintOnVar(x,store,nil,nil)
returns two lists, the rst one with the constraints
in store where x is involved in and the second
one with the rest of the store. All these operators are domain independent. The operators
EvaluateGroundFormule(c) evaluate the truth
value of a ground formula according to the interpretation I, and ReviseDxWRTc return the set
of values in Dx that satisfy c, i.e., this operator implements RD of rule Node-Consistency
in gure 1.
Figure 5 describes the specication of the operator ReviseDxWRTc in the particular case of an
integer signature. ReviseDxWRTc makes use of a
canonical form for the constraints because of efciency reasons. This canonical form is obtained
applying a preprocessing step on the input term.
Once we realise that there are rules that depend on the general process of constraint solving
and rules that depend on the specic structure
over which we want to solve Binary CSPs, it is
natural to think about a general solver for solving
CSP. Using this idea we have designed a general
framework for constraint solving and implemented
a computational system for solving Binary CSP
over two discrete domains, the integer numbers
and the nite domains. In this way, solving Binary CSP(X ) needs only to specify a module for
the particular signature associated to X .
7
csp
x , y : var ; lv : l i s t [ var ] ; v : Type ; n : int ; F : bool ;
D,RD: domain ; c : formula ; lmc , l e c ,C , st or e , l1 : l i s t [ formula ] ;
t w o l i s t s : tuple [ l i s t [ formula ] , l i s t [ formula ] ] ;
rules for
global
[]
Verify ? NC (CSP [ lmc , l e c , c . C, s to re ] )
=>
where
( l i s t [ var ] ) y . lv := ( ) GetVarOfAtomicFormula ( c )
switch
case
occurs y in l e c then
where
( l i s t [ formula ] ) x = v . l1 := ( ) GetVarInHead ( y , l e c
switch
case
EvaluateGroundFormula ( r ep la ce ( x , v , c ) )
then
, nil )
CSP [ lmc , x=v . l1 , C, s to re ]
otherwise
CSP [ x in ? empty . lmc , l1 ,C , s tor e ]
end
otherwise
where
where
switch
case
( l i s t [ formula ] ) x in ? D. l1 := ( ) GetVarInHead ( y , lmc , n il )
RD := ( ) ReviseDxWRTc ( x in ? D, c )
RD != D then
CSP [ x in ? RD. l1 , l e c , append ( 1?th ( t w o l i s t s ) ,C) , 2?th ( t w o l i s t s ) ]
where ( tuple [ l i s t [ formula ] , l i s t [ formula ] ] )
t w o l i s t s := ( ) GetConstraintsOnVar ( x , st or e , ni l , n i l )
otherwise
end
end
end
CSP [ x in ? D. l1 , l e c , C, s to re ]
Figure 4: Operator Verify NC: Verication of Node-Consistency
Checking and a version of Full Lookahead including the First Fail Principle to select the next variable to instantiate5.
It is important to note that rewrite rules and
strategies allow an easy formalisation of this kind
of strategies, but it is dicult to implement
heuristics like Backjumping. The basic strategy operator dk, dont know choose, is powerful
enough to implement choice point like heuristics,
but it does not allow to jump in the search tree.
Concerning the same operator, global variables
are not available, so implementation of branch
and bound techniques, widely used for optimisation problems, are not evident.
constraint. A lot of combinatorial problems involve this kind of constraints. For example, in
scheduling problems these constraints come from
the fact that several tasks must use the same resource and the limited capacity of that resource
does not allow to perform all tasks at a same time
[20]. Let T askij the start time of task i of job
j and dij the duration of task i of job j . On a
machine performing a simple task at a time, the
capacity constraints enforce the mutual exclusion
for each pair of tasks assigned to the same machine. If we consider task k of jobs i and j , the
fact that on machine k job i runs before job j or
vice versa can be expressed by the following disjunctive constraint
4 Handling Disjunctive Constraints
T askkj ? T askki + dki _ T askki ? T askkj + dkj
In order to perform all tasks using the same
The combination of two elementary constraints resource
a sequential order must be established,
with a disjunction operator is called a disjunctive these precedence
relations that are not known
5 The First Fail Principle is also known as Minimum a priori are determinated by the solution to a
Domain.
scheduling problem. This feature changes the
8
domain
x : var ; D: domain ; k1 , k2 , lowbound : int ;
rules for
global
[]
ReviseDxWRTc ( x in ? D, k1 ( ) x (+) k2 >=? 0 )
=>
where
lowbound :=( ) ?k2 /k1
switch
case
lowbound <= MaxOfDomain(D)
UpdateMinOfDomain (D, lowbound )
then
otherwise
empty
end
end
Figure 5: Operator ReviseDxWRTc: Revise Domain for integers
csp
implicit
[ ] L oc alC ons is te nc yF orE l eme nta ryC ons tr ai nts =>
repeat + ( f i r s t ( NodeConsistency j j ArcConsistency ) ;
f irst ( fi rs t ( Ins ta ntia tio n ) ;
f i r s t ( Elimination j j id )
s t r a t e g i e s for
jj
f i r s t ( F a l s i ty )
jj
end
)
id
)
Figure 6: Strategy for implementing Local Consistency
nature of the problem, and no ecient polynomial algorithm can be exhibited for solving all
problems involving disjunctive constraints. Some
techniques to deal with this kind of problems are
Choice Point [18], introduction of (0/1) Binary
Variables [22], and Constructive Disjunction [19].
Figure 8 presents ConstructiveDisjunction a
set of rules to deal with CSPs involving
T disjunctive
constraints, where D0 x = Dx n fv 2 Dx j (8i =
1; ::; k; j = 1; ::; ni) c?ij jx=v = Fg.
Rule Post-Constraint establishes that if a disjunctive constraint is composed of only one disjunct then this disjunct is posted as an elementary
constraint and the original disjunctive constraint
is eliminated. Rule Eliminate-Disjunct express
the fact that when a disjunct is inconsistent with
respect to the membership constraints associated
to the variables in the disjunct, this disjunct is
eliminated from the disjunctive constraint. If a
disjunct is a ground formula and its truth value
is true then the whole disjunctive constraint is
eliminated, that is the idea of rule EliminateDisjunction. Rule Split-Disjunctions splits
the set of disjunctive constraints in two subsets
whose set of variables are disjoints. The idea
behind this rule is to obtain a set of connected
graphs when it is applied repeatedly on the set
of disjunctive constraints. Finally, rule DomainReduction veries local consistency using a constructive disjunction approach, impossible combinations of values that are common to all alternatives of a set of disjunctive constraints are eliminated.
The rules in ConstructiveDisjunction can
be used to carry out a preprocessing step in order to eliminate some values, before any a priori choice between the disjuncts of the disjunctive
constraints, as is expressed by the following strategies. Let
CD :: [Split-Disjunctions;
Domain-Reduction; [Post-Constraint j
Eliminate-Disjunct j
Eliminate-Disjunction]]
So, the strategy
9
s t r a t e g i e s for
implicit
csp
[ ] Forward ? Checking =>
L oca lC o ns is te ncy Fo rE l emen ta ryC ons tr ai nts ;
repeat (
f i r s t ( GetDisjunctiveNormalForm ) ;
f i r s t ( dk ( P os t F i r s t C o n s tr a i nt j j PostSecondConstraint ) j j f i r s t ( PostConstraint ) ) ;
L oca lC o ns is te ncy Fo rE le men tar yC o ns tr ain ts ;
dk (
f i r s t ( Enumerate1 ) ;
f i r s t ( Elimination j j id ) ;
f i r s t ( Node ? Consistency ? for ? Elementary ? Constraints j j id )
jj
first
)
)
( Enumerate2 )
end
[ ] Full ? Lookahead ? With ? Minimum ? Domain =>
L oca lC o ns is te ncy Fo rE l emen ta ryC ons tr ai nts ;
repeat (
f i r s t ( GetDisjunctiveNormalForm ) ;
f i r s t ( dk ( P os t F i r s t C o n s tr a i nt j j PostSecondConstraint ) j j
L oca lC o ns is te ncy Fo rE le men tar yC o ns tr ain ts ;
f i r s t ( GetVarWithMinimumDomain ) ;
dk (
f i r s t ( Enumerate1 ) ;
f i r s t ( Elimination j j id ) ;
Lo cal C o nsi s ten cyF o rE le ment ar yC o nst ra in ts
jj
first
)
)
first
( PostConstraint ) ) ;
( Enumerate2 )
end
Figure 7: Strategies for implementing Hybrid Techniques
variables- are communicated through membership
[LocalConsistencyForElementaryConstraints;constraints. The algorithm stops when there are
CD]
no more changes in these constraints.
veries local consistency for a set of elementary Theorem 2 If we can decompose a set of disjuncand disjunctive constraints using a constructive tive constraints in M subgraphs, the worst case
disjunction and a graph decomposition approach. time complexity of our algorithm is bounded by
In [6] we propose an approach for systematic M 2ND?M +1 , where ND is the total number of
manipulation of disjunctive constraints. We rstly disjunctive constraints.
decompose a set of constraints in two subproblems, the rst one with all the elementary con- Proof: See [6].
straints and the second one with all the disjunctive
constraints. A graph decomposition algorithm is This theorem means that if we can decompose
applied to the set of disjunctive constraints in the set of disjunctive constraints in several suborder to obtain the maximum number of sub- problems we can do better than the existing apsets whose sets of variables are disjoints. Then proaches, like choice point. This approach can
arc consistency is veried for the set of elemen- be used for solving scheduling problems where
tary constraints and we use constructive disjunc- disjunctive constraints are the main complexity.
tion to deal with the subsets of disjunctive con- In [7] we show how we can reduce the search
straints in order to prune the search space. The space and eliminate some disjunctions when our
results -elimination of impossible values for the approach is used as a preprocessing step.
10
[Post ? Constraint]
V
W
C ^ i=1;::;m Vj =1;::;ni c?ij W
) C ^ c?k1 ^ i=1;::;m;i6=k j =1;::;ni c?ij
Vif nk =(x12? D ) ^ C ^ V
W
?
[Eliminate ? Disjunct]
x
xV
2X
i=1;::;m j =1;::;ni cij
?
) Vx2X (x 2 DWx ) ^ C ^ W
?
?
i=1;::;m
;i=6 k j =1;::;ni cij ^ j =1;::;nk;j 6=l ckj
V
?
?
if SolDV( x2X (xW2 Dx ) ^ ckl ) = ;
[Eliminate ? Disjunction] C ^ i=1
c?
;::;m j =1;::;n
i ij
V
W
) C ^ i=1;::;m;i=6 k j =1;::;ni c?ij
if 9 l 2V[1; ::; nkW] : c?kl = T
?
[Split ? Disjunctions]
C ^ i=1
;::;m jW
=1;::;ni cij
V
c? ^
) VC ^ i=1;::;k
i ij
W j=1;::;n
?
i=k+1;::;m j =1;::;ni cij
if SSi=1;::;k;j=1;::;ni V ar(c?ij ) \
V ar(cW?ij ) = ;
i=k+1;::;m;j =1;::;n
i
V
?
[Domain ? Reduction]
x 2V Dx ^ C W^ i=1;::;k j =1;::;ni c?ij ^
c?
i=k+1;::;m j =1;::;nV
i ij
?
0
) Vx 2 D x ^WC ^ i=1;::;k Wj =1;::;ni c?ij ^
?
i=k+1
;::;m j =1;::;ni cij
S
if x 2 i=1;::;k;j=1;::;ni V ar(c?ij )
and Dx 6= D0 x
Figure 8: ConstructiveDisjunction: Rewrite rules for constructive disjunction in Binary CSP
5 Conclusion
tected problems concerning the implementation of
heuristics that require to jump in the search tree,
and we are also working on the implementation of
branch and bound techniques.
As our aim in this work was only to apply the
expressive power of computational systems to better understand constraint solving we did not care
about eciency, so as future work we are interested in eciency considerations related to our
implementation. We are also interested in the development of the prototype in order to validate it
solving real life problems. From a more theoretical point of view we are interested in detection
and elimination of redundancy in CSP using syntactical methods.
We have implemented a prototype of a computational system for solving Binary CSPs. We
have veried how computational systems are an
easy and natural way to describe and manipulate
Binary CSPs. Using this approach we have investigated the description of specic techniques
for constraint manipulation. We have proposed
an approach for systematic manipulation of disjunctive constraints, useful to solve, for example,
scheduling problems where disjunctive constraints
are the main complexity.
The main contribution of this work can be seen
from two points of view. First, we have formalised
algorithms to solve Binary CSPs in a way that
makes explicit dierence between actions and control, allowing us to better understand the algo- References
rithms that we have used for constraint solving. [1] Christian Bessiere. Arc-consistency and arcconsistency again. Articial Intelligence, 65:179{190,
This framework makes easier to prototype new
1994.
heuristics and prove termination, tasks that until now were not obvious in black box like algo- [2] Christian Bessiere and Jean-Charles Regin. An arcconsistency algorithm optimal in the number of conrithms. Second, we have extended the domain of
straint checks. In Proceedings of the Workshop on
application of Rewriting Logic.
Constraint Processing, ECAI'94, Amsterdam, The
We are currently working to solve the deNetherlands, pages 9{16, 1994.
11
[3] Peter Borovansky, Claude Kirchner, and Helene
Kirchner. Strategies and Rewriting in ELAN. In
Bernard Gramlich and Helene Kirchner, editors, Proceedings CADE-14 Workshop on Strategies in Automated Deduction, pages 13{24, Townsville, Australia,
July 1997.
[4] Maurice Bruynooghe and Raf Venken. Backtracking.
In Stuart C. Shapiro, editor, Encyclopedia of Articial Intelligence, volume 1. Addison-Wesley Publishing Company, 1992. Second Edition.
[5] Carlos Castro. Solving Binary CSP Using Computational Systems. In Jose Meseguer, editor, Proceedings of the First International Workshop on
Rewriting Logic and its Applications, RWLW'96, volume 5, pages 245{264, Asilomar, Pacic Grove, CA,
USA, September 1996. Electronic Notes in Theoretical Computer Science.
[6] Carlos Castro. An Approach for Achieving Local Consistency in Binary CSP Involving Disjunctive Constraints. In XXIII Conferencia Latinoamericana de
Informatica, CLEI'97, Valparaso, Chile, November
1997. To appear.
[7] Carlos Castro. An Approach for Systematic Manipulation of Disjunctive Constraints in CSP: An Application to Scheduling Problems. To be submitted, 1997.
[8] E. C. Freuder. Using Metalevel Constraint Knowledge to Reduce Constraint Checking. In Proceedings
of the Workshop on Constraint Processing, ECAI'94,
Amsterdam, The Netherlands, pages 27{33, 1994.
[9] Eugene C. Freuder. Synthesizing Constraint Expressions. Communications of the ACM, 21(11):958{966,
November 1978.
[10] Claude Kirchner, Helene Kirchner, and Marian Vittek. Designing Constraint Logic Programming Languages using Computational Systems. In Pascal Van
Hentenryck and Vijay Saraswat, editors, Principles
and Practice of Constraint Programming. The Newport Papers, pages 131{158. The MIT press, 1995.
[11] Claude Kirchner, Helene Kirchner, and Marian Vittek. ELAN, User Manual. INRIA Lorraine &
CRIN, Campus scientique, 615, rue du Jardin
Botanique, BP-101, 54602 Villers-les-Nancy Cedex,
France, November 1995.
[12] Vipin Kumar. Algorithms for Constraint-Satisfaction
Problems: A Survey. Articial Intelligence Magazine,
13(1):32{44, Spring 1992.
[13] Alan K. Mackworth. Consistency in Networks of Relations. Articial Intelligence, 8:99{118, 1977.
[14] Alan K. Mackworth and Eugene C. Freuder. The
Complexity of Some Polynomial Network Consistency
Algorithms for Constraint Satisfaction Problems. Articial Intelligence, 25:65{74, 1985.
[15] Jose Meseguer. Conditional rewriting logic as a unied model of concurrency. Theoretical Computer Science, 96(1):73{155, 1992.
[16] Roger Mohr and Thomas C. Henderson. Arc and Path
Consistency Revisited. Articial Intelligence, 28:225{
233, 1986.
[17] Edward Tsang. Foundations of Constraint Satisfaction. Academic Press, 1993.
[18] Pascal van Hentenryck. Constraint Satisfaction in
Logic Programming. The MIT press, 1989.
[19] Pascal van Hentenryck, Vijay Saraswat, and Yves
Deville. Design, Implementation, and Evaluation of
the Constraint Language cc(FD). In Constraint Programming: Basic and Trends. Selected Papers of the
22nd Spring School in Theoretical Computer Sciences. Springer-Verlag, Ch^atillon-sur-Seine, France,
May 1994.
[20] Mark G. Wallace. Applying Constraints For Scheduling. In Mayoh B and Penjaam J, editors, Constraint Programming, NATO ASI Series. SpringerVerlag, 1994.
[21] Richard J. Wallace. Why AC-3 is almost always better
than AC-4 for establishing arc concsistency in CSPs.
In Proceedings 13th International Joint Conference
on Articial Intelligence, Chambery (France), pages
239{245, 1993.
[22] H.P. Williams. Model Building in Mathematical Programming. J. Wiley and Sons, New York, 1978.
[23] Martin Zahn and Walter Hower. Backtracking along
with constraint processing and their time complexities. Journal of Experimental and Theoretical Articial Intelligence, 8:63{74, 1996.
12
Download