Document 10968890

advertisement
A model of onstraint solvers by haoti iteration adapted to
value withdrawal explanations
LIFO, EMN
Gerard Ferrand, Willy Lesaint, Alexandre Tessier
publi, rapport de reherhe
D1.1.1
Abstrat
The aim of this report is to provide the theoretial foundations of domain redution. The model is well suited to the solvers on nite domains whih are used on
the respetive platforms of eah partner of the projet: GNU-Prolog (INRIA), CHIP
(COSYTEC) and PaLM (EMN). A omputation is formalized by a haoti iteration
of operators and the result is desribed as a losure. The model is well suited to the
denition of traes and explanations whih will be useful for the debugging of onstraint programs. This report only deals with the redution stage. It will be extended
to the labeling and the host language in next reports.
1
Introdution
Constraint Logi Programming (CLP) [12℄ an be viewed as the reunion of two programming paradigms : logi programming and onstraint programming. Delarative debugging
of onstraints logi programs has been treated in previous works and tools have been produed for this aim during the DiSCiPl (Debugging Systems for Constraint Programming)
ESPRIT Projet [8, 15℄. But these works deal with the lausal aspets of CLP. This report
fous on the onstraint level alone. The tools used at this level strongly depend on the
onstraint domain and the way to solve onstraints. Here we are interested in a wide eld
of appliations of onstraint programming: nite domains and propagation.
The aim of onstraint programming is to solve Constraint Satisfation Problems (CSP)
[16℄, that is to provide an instantiation of the variables whih is orret with respet to
the onstraints.
The solver goes toward the solutions ombining two dierent methods. The rst one
(labeling) onsists in partitioning the domains until to obtain singletons and, testing them.
The seond one (domain redution) redues the domains eliminating some values whih
annot be orret aording to the onstraints. Labeling provides exat solutions whereas
domain redution simply approximates them. In general, the labeling alone is very expensive and a good ombination of the two methods is more eÆient. In this paper labeling
is not really treated. We onsider only one branh of the searh tree: the labeling part is
seen as additional onstraint to the CSP. In future work, we plan to extend our framework
in order to fully take labeling and the whole searh tree (instead of a single branh) into
aount.
1
This kind of omputation is not easy to debug beause CSP are not algorithmi programs [13℄. The onstraints are re-invoked aording to the domain redutions until a
x-point is reahed. But the order of invoation is not known a priori and strongly depends on the strategy used by the solver.
The main ontribution of this report is to formalize the domain redution in order
to provide a notion of explanation for the basi event whih is \the withdrawal of a
value from a domain". This notion of explanation is essential for the debugging of CSP
programs. Indeed, the disappearane of a value from a domain may be a symptom of an
error in the program. But the error is not always where the value has disappeared and
an analysis of the explanation of the value withdrawal is neessary to loate the error.
[9℄ provides a tool to nd symptoms, this paper provides a tool whih ould be used to
nd errors from symptoms. Explanations are a tool to help debugging: we extrat from a
(wide) omputation a strutured part (a proof tree or an explanation tree) whih will be
analyzed more eÆiently.
We are inspired by a onstraint programming language over nite domains, GNUProlog [6℄, beause its glass-box approah allows a good understanding of the links between
the onstraints and the rules. But our model is suÆiently general to take the solver of
eah partner into aount, that is GNU-Prolog (INRIA), CHIP (COSYTEC) and PaLM
(EMN).
We provide explanations in the general ase of hyper-ar onsisteny. Obviously, this
denition of explanations is orret for weaker onsistenies usually used in the implemented solvers. To be easily understandable, we provide examples in the ar-onsisteny
ase.
An explanation is a subset of operators used during the omputation and whih are
responsible for the removal of a value from a domain. Several works shown that detailed
analysis of explanations have a lot of appliations [10, 11℄. But these appliations of explanations are outside the sope of this report (see [11℄). Here, our denitions of explanations
are motivated by appliations to debugging, in partiular to error diagnosis.
An aspet of the debugging of onstraint programming is to understand why we have
a failure (i.e. we do not obtain any solution); this problem has been raised in [2℄. This
ase appears when a domain beomes empty, that is no value of the domain belongs to a
solution. So, an explanation of why these values have disappeared provides an explanation
of the failure.
Another aspet is error diagnosis. Let us assume an expeted semantis for the CSP.
Consider we are waiting for a solution ontaining a ertain value for a variable, but this
value does not appear in the nal domain. An explanation of the value withdrawal help us
to nd what is wrong in our program. It is important to note that the error is not always
the onstraint responsible of the value withdrawal. Another onstraint may have made
a wrong redution of another domain whih has nally produed the withdrawal of the
value. The explanation is a strutured objet in whih this information may be founded.
The report is organized as follows. Setion 2 gives some notations and basi denitions
for Constraint Satisfation Problems. Setion 3 desribes a model for domain redution
based on redution operators and haoti iteration. Setion 4 assoiates dedution rules
to this model. Setion 5 uses dedution rules in order to build explanations. Next setion
is a onlusion.
2
2
Preliminaries
We provide the lassial denition of a onstraint satisfation problem as in [16℄. The
notations used are natural to express basi notions of onstraints involving only some
subset of the set of all variables.
Here we only onsider the framework of domain redution as in [5, 6, 17, 18℄. More
general framework is desribed in [4, 14℄.
A Constraint Satisfation Problem (CSP) is made of two parts, the syntati part:
a nite set of variable symbols (variables in short) V ;
a nite set of onstraint symbols (onstraints in short) C ;
a funtion var : C ! P (V ), whih assoiates with eah onstraint symbol the set of
variables of the onstraint;
and a semanti part.
For the semanti part, we need some preliminaries. We are going to onsider various
families f = (fi )i2I . Suh a family is identied with the funtion i 7! fi , itself identied
with the set f(i; fi ) j i 2 I g.
We onsider a family (Dx )x2V where eah Dx is a nite non empty set alled the domain
of the variable x (domain of x in short). In order to have simple and uniform denitions
of monotoni operators on a power-set, we use a set whih is
similar to an Herbrand base
S
in logi programming. We dene the global domain by G = x2V (fxg Dx ). We onsider
subsets d of G , i.e. d G . We denote by djW the restrition of a set d G to a set of
variables W V , that is djW = f(x; e) 2 d j x 2 W g.
We use the same notations for the tuples. A global tuple t is a partiular d suh that
eah variable appears only one: t G and 8x 2 V , tjfxg = f(x; e)g. A tuple t on W V ,
is dened by t G jW and 8x 2 W , tjfxg = f(x; e)g. So, a global tuple is a tuple on V .
Then, the semanti part is dened by:
the family (Dx )x2V ,
the family (T )2C whih is dened by: for eah 2 C , T is a set of tuple on var ()
i.e. eah t 2 T is identied with a set f(x; e) j x 2 var ()g.
A global tuple t is a solution of the CSP if 8 2 C; tjvar () 2 T .
For any d G , we need another notation: for x 2 V , we dene dx = fe 2 Dx j (x; e) 2
dg. So, we an note the following points:
for = G , x = x,
= Sx2V (f g x);
for 0 G , 0 , 8 2 x 8 2 , jfxg = f g x;
for , G jW , 8 2 n
d
d
D
x
d
d; d
x
V
W
d
d
d
V
d
x
d
x
V; d
0,
x
d
d
x
V
x
W; d
3
= ;.
Example 1 CSP
Let us onsider the CSP dened by:
= fx; y; z g
V
= fx < y; y < z; z < xg
C
var suh that: var (x < y) = fx; yg, var (y < z ) = fy; z g and var (z < x) = fx; z g.
= Dy = Dz = f0; 1; 2g, that is:
G = f(x; 0); (x; 1); (x; 2); (y; 0); (y; 1); (y; 2); (z; 0); (z; 1); (z; 2)g
x
D
suh that:
Tx<y = ff(x; 0); (y; 1)g; f(x; 0); (y; 2)g; f(x; 1); (y; 2)gg
Ty<z = ff(y; 0); (z; 1)g; f(y; 0); (z; 2)g; f(y; 1); (z; 2)gg
Tz<x = ff(x; 1); (z; 0)g; f(x; 2); (z; 0)g; f(x; 2); (z; 1)gg
T
For a given CSP, one is interested in the omputation of the solutions. The simplest
method onsists in generating all the tuples from the initial domains, then testing them.
This generate and test method is learly expensive for wide domains. So, one prefers to
redue the domains rst (\test" and generate).
To be more preise, to redue the domains means to replae eah Dx by a subset of
Dx . But in this ontext, eah subset of Dx an be denoted by dx for d G . Suh dx
is alled the domain of x and d is alled the global domain. Dx is merely the greatest
domain
of x. In fat, the redution of domains will be applied to all domains, but sine
S
d =
x2V (fxg dx ), it amounts to the redution of the global domain d.
Here, we fous on the redution stage. Let d the global domain. Intuitively, if t
is a solution of the CSP, then t d and we attempt to approah the smallest domain
ontaining all the solutions of the CSP. So this domain must be an \approximation" of
the solutions aording to an ordering whih is exatly the subset ordering .
We desribe in the next setion a model for the omputation of suh approximations.
3
Domain redution
We propose here a model of the operational semantis for the omputation of approximations. It will be well suited to dene notions of basi events neessary for trae analysis,
and explanations useful for debugging. Moreover main lassial results [4, 5, 14℄ are proved
again in this model.
A set of operators (loal onsisteny operators) is assoiated to eah onstraint. The
intersetion between the global domain and the domain obtained by appliation of a loal
onsisteny operator provides a new global domain. Finally, in order to always reah a
x-point (that is the approximation we look for), all the operators will be applied, as many
time as neessary, aording to a haoti iteration.
A way to ompute an approximation of the solutions is to assoiate with the onstraints
some loal onsisteny operators. A loal onsisteny operator is applied to the whole
global domain. But in fat, the result only depends on a restrition of it to a subset of
4
variables Win V . The type of suh an operator is (Win ; Wout ) with Win ; Wout V .
Only the domains of Wout are modied by the appliation of this operator. It eliminates
from these domains some values whih are inonsistent with respet to the domains of
Win .
Denition 1 A loal onsisteny operator of type (Win ; Wout ), with Win ; Wout
monotoni funtion
( )jV nW
r d
out
r
: P (G )
! P (G ) suh that: 8 G ,
V
is a
d
= G jV nW ,
out
( ) = r(djW )
r d
in
We an note that:
( )jV nW
r d
out
( )jW
r d
out
is independent of d,
only depends on djW ,
in
a loal onsisteny operator is not a ontrating funtion.
Denition 2 We say a domain d is r-onsistent if d r(d), that is djW
out
( )jW .
r d
out
We provide an example in the obvious ase of ar-onsisteny.
Example 2 Ar-onsisteny
Let 2 C with var () = fx; yg and d G . The property of ar-onsisteny for d is:
(1) 8e 2 dx ; 9f
(2) 8f
2
y
d ;
2
9 2
e
y
d ;
x
d ;
f(
f(
) (y; f )g 2 T ,
x; e ;
) (y; f )g 2 T .
x; e ;
The loal onsisteny operator r assoiated to (1) has the type (fyg; fxg) and is dened
by: r(d) = G jV nfxg [ f(x; e) 2 G j 9(y; f ) 2 d; f(x; e); (y; f )g 2 T g. It is obvious that (1)
() d r(d), that is d is r-onsistent. We an dene in the same way the operator of
type (fxg; fyg) assoiated to (2).
Example 3 Continuation of example 1
Let us onsider the onstraint x < y dened in example 1. For d = G , the property of aronsisteny provided in the example above is assoiated to: r1 (d) = G jfy;zg [f(x; 0); (x; 1)g
and r2 (d) = G jfx;zg [ f(y; 1); (y; 2)g.
The solver is desribed by a set of suh operators assoiated with the onstraints of the
CSP. We an hoose more or less aurate loal onsisteny operators for eah onstraint
(in general, the more aurate they are, the more expensive is the omputation).
We assoiate to these operators, redution operators in order to ompute the intersetion with the urrent global domain.
Denition 3 The redution operator assoiated to the loal onsisteny operator r is the
monotoni and ontrating funtion
d
7! \
d
( ).
r d
5
All the solvers proeeding by domain redution use operators with this form. For GNUProlog, we assoiate to eah onstraint as many operators as variables in the onstraint.
Example 4 GNU-Prolog
In GNU-Prolog, suh operators are written x in r [6℄, where r is a range dependent on
domains of a set of variables. The rule x in 0..max(y) is the loal onsisteny operator of type (fyg; fxg) whih omputes f0; 1; : : : ; max(dy )g where max(dy ) is the greatest
value in the domain of y. It is the loal onsisteny operator dened by r(d)jfxg =
f(x; e) j 0 e max(dy )g. The redution operator assoiated to this loal onsisteny
operator omputes the intersetion with the domain of x and is implemented by the rule
x in 0..max(y):dom(x).
The loal onsisteny operators we use must not remove solutions of the CSP. We
formalize it by the following denition.
Denition 4 A loal onsisteny operator r is orret if, for eah d G , for eah solution
t
,
t
) d
t
( ).
r d
A loal onsisteny operator is assoiated to a onstraint of the CSP. Suh an operator must obviously keep the solutions of the onstraint. This is formalized by the next
denition and lemma.
and Wout var (). A loal onsisteny operator r of type
(Win ; Wout ) is orret with respet to the onstraint if, for eah d G , for eah t 2 T ,
t d ) t r (d).
Denition 5 Let
2
C
Lemma 1 If r is orret with respet to , then r is orret.
Proof. Let d G and s d a solution of the CSP. sjvar() 2 T, so sjvar () ( ). Moreover sjV nvar () G jV nvar () = r(d)jV nvar () beause Wout var ().
r d
Note that the onverse does not hold.
Example 5 GNU-Prolog
The rule r : x in 0..max(y) is orret with respet to the onstraint dened by var () =
fx; yg and T = ff(x; 0); (y; 0)g; f(x; 0); (y; 1)g; f(x; 1); (y; 1)gg (Dx = Dy = f0; 1g and is
the onstraint x y).
Intuitively, the solver applies the redution operators one by one replaing the global
domain with the one it omputes. The omputation stops when some domain beomes
empty (in this ase, there is no solution), or when the redution operators annot redue
the global domain anymore (a ommon x-point is reahed).
From now on, we denote by R a set of loal onsisteny operators. The ommon xpoint of the redution operators assoiated to R from a global domain d is a global domain
0
0
0
0
0
0
d d suh that 8r 2 R, d = d \ r (d ), that is 8r 2 R, d r (d ). The greatest ommon
x-point is the greatest d0 d suh that 8r 2 R, d0 is r-onsistent. To be more preise:
6
f 0 G j 0 ^8 2
and is denoted by
# ( ).
Denition 6
R
max d
d
CL
d
r
R; d
0 r(d0 )g is the downward losure of
d
by
d; R
The downward losure is the most aurate set whih an be omputed using a set of
orret operators. Obviously, eah solution belongs to this set. It is easy to verify
T rthat
C L # (d; R) exists and an be obtained by iteration of the operator d 7! d \
r2R (d).
There exists another way to ompute C L # (d; R) alled the haoti iteration that we are
going to reall.
The following denition is taken up to Apt [3℄.
A run is an innite sequene of operators of R, that is, a run assoiates to eah i 2 IN
(i 1) an element of R denoted by ri . A run is fair if eah r 2 R appears in it innitely
often, that is fi j r = ri g is innite. Let us dene a downward iteration of a set of operators
with respet to a run.
Denition 7 The downward iteration of the set of loal onsisteny operators R from the
global domain d G with respet to the run r1 ; r2 ; : : : is the innite sequene d0 ; d1 ; d2 ; : : :
indutively dened by:
1.
0
d
= d;
2. for eah
i
2 IN,
d
i+1
= di \ ri+1 (di ).
Its limit is denoted by d! = \i2IN di . A haoti iteration is an iteration with respet to a
fair run.
T
The operator d 7! d \ r2R r(d) may redue several domains at eah step. But the
omputations are more intriate and some an be useless. In pratie haoti iterations
are preferred, they proeed by elementary steps, reduing only one domain at eah step.
The next well-known result of onuene [3, 7℄ ensures that any haoti iteration reahes
the losure. Note that, sine is a well-founded ordering (i.e. G is a nite set), every
iteration from d G is stationary, that is 9i 2 IN; 8j i,rj +1 (dj ) \ dj = dj , that is
j
j +1 (dj ).
d r
Lemma 2 The limit of every haoti iteration of the set of loal onsisteny operators
from
d
G
is the downward losure of
d
by
R
.
R
Let d0 ; d1 ; d2 ; : : : be a haoti iteration of R from d with respet to
1
2
! be the limit of the haoti iteration.
r ; r ; : : :. Let d
!
i
C L # (d; R) d : For eah i, C L # (d; R) d , by indution: C L # (d; R) 0
i
i+1 (C L # (d; R)) r i+1 (di )
d = d. Assume C L # (d; R) d , C L # (d; R) r
by monotoniity. Thus, C L # (d; R) di \ ri+1 (di ) = di+1 .
! C L # (d; R): There exists k 2 IN suh that d! = dk beause is a
d
well-founded ordering. The run is fair, hene dk is a ommon x-point of the
set of redution operators assoiated to R, thus dk C L # (d; R) (the greatest
ommon x-point).
Proof.
The fairness of runs is a onvenient theoretial notion to state the previous lemma.
Every haoti iteration is stationary, so in pratie the omputation ends when a ommon
7
x-point is reahed. Moreover, implementations of solvers use various strategies in order
to determinate the order of invoation of the operators. These strategies are used so as to
optimize the omputation, but this is not in the sope of this report.
In pratie, when a domain beomes empty, we know that there is no solution, so an
optimization onsists in stopping the omputation before the losure is reahed. In that
ase, we say that we have a failure iteration.
We have provided in this setion a model of the operational semantis for the solvers on
nite domains using domain redution. This model is language independent and enough
general in order to be used for the platform of eah partner: GNU-Prolog, CHIP and
PaLM.
4
Dedution rules
The appliation of a loal onsisteny operator an be onsidered as a basi event. But
for the notion of explanation, we need to be more preise. So, in this setion, we attempt
to explain in detail the appliation of a loal onsisteny operator.
Note that we are interested by the value withdrawal, that is when a value is not in
a global domain but in its omplementary. So, we onsider this omplementary and the
\duals" of the loal onsisteny operators. By this way, at the same time we redue the
global domain, we build its omplementary. We assoiate natural rules to these operators.
These rules will be the onstrutors of the explanations.
First we need some notations. Let d = G n d. In order to help the understanding, we
always use d for the omplementary of a global domain and d for a global domain.
Denition 8 Let r an operator, we denote by re the dual of r dened by:
( ).
8 G e(
d
)=
;r d
r d
We need to onsider sets of suh operators as for loal onsisteny operators. Let
e) exists and is the
r
r
R
d
R
C L " (d; R
e = fe j 2 g. The upward losure of by e, denoted by
least 0 suh that 0 and 8 2 , e( 0 ) 0 .
R
d
d
d
r
R
r d
d
Next lemma ensures that the downward losure of a set of loal onsisteny operators
from a global domain d is the omplementary of the upward losure of the set of dual
operators from the omplementary of d.
Lemma 3
CL
" ( e) =
d; R
CL
#(
d; R
).
Proof. straightforward
By the same way we dened a downward iteration of a set of operators from a domain,
we dene an upward iteration.
The upward iteration of Re from the global domain d G with respet to re1 ; re2 ; : : : is
the innite sequene d0 ; d1 ; d2 ; : : : indutively dened by:
1.
0
d
= d,
i+1 (di ).
2. di+1 = di [ rg
8
We an rewrite the seond item: di+1 = di [ ri+1 (di ). It is then obvious, that we add
to di , the elements of di removed by ri+1.
The link between the downward and the upward iteration learly appears by noting
that: di+1 = di \ ri+1 (di ) and [j 2IN dj = C L " (d; Re) = C L # (d; R).
We have provided two points of view for the redution of a global domain d with respet
to a run r1 ; r2 ; : : :. In the previous setion, we onsider the redued global domain, but
in this setion, we onsider the omplementary of this redued global domain, that is the
set of elements removed of the global domain. As a loal onsisteny operator \keeps"
elements in a domain, its dual \adds the others" in the omplementary.
Now, we assoiate dedution rules to these dual operators. These rules are natural to
build the omplementary of the global domain and well suited to provide proof trees.
Denition 9 A dedution rule of type (Win ; Wout ) is a rule h
and
B
G jW
in
.
B
suh that
h
2 G jW
out
For eah operator r 2 R of type (Win ; Wout ), we denote by Rr a set of dedution rules
of type (Win ; Wout ) whih denes re, that is re is suh that: re(d) = fh 2 G j 9B d; h
B 2 Rr g. For eah operator, this set of dedution rules exists. There exists possibly many
suh sets, but one is natural.
We provide illustrations of this model on dierent onsisteny examples. Let us begin
with the obvious ar onsisteny ase.
Example 6 Ar onsisteny
Let us onsider the loal onsisteny operator r dened in example 2 by:
r (d) = G jV nfxg [ f(x; e) 2 G j 9(y; f ) 2 d; f(x; e); (y; f )g 2 T g.
So, re(d) = r(d) = f(x; e) 2 G j 8(y; f ) 2 d; f(x; e); (y; f )g 62 T g.
Let B(x;e) = f(y; f ) j f(x; e); (y; f )g 2 T g. Then,
B(x;e) d
, 8(y; f ) 2 G ; [f(x; e); (y; f )g 2 T ) (y; f ) 2 d℄
, 8(y; f ) 2 G ; [(y; f ) 2 d ) f(x; e); (y; f )g 62 T℄
, 8(y; f ) 2 d; f(x; e); (y; f )g 62 T
So, re(d) = f(x; e) 2 G j B(x;e) dg.
Finally, the set of dedution rules assoiated to r is Rr = f(x; e) B(x;e) j (x; e) 2 dg.
Example 7 Continuation of example 1
Let us onsider the CSP of example 1. Two loal onsisteny operators are assoiated to
the onstraint x < y: r1 of type (fyg; fxg) and r2 of type (fxg; fyg). The set of dedution
rules Rr1 assoiated to r1 ontains the three dedution rules:
(x; 0)
(x; 1)
(x; 2)
f(
f(
;.
y;
y;
1); (y; 2)g,
2)g, and
9
'$'$
&%&%
G j fy g
G jfxg
````` T
``
`````` `````
``````
bb
``b`b``
bb```````
B
bb
h
bb
XXXX (((bb(
XX(
((((((( XXXXX
Figure 1: The partiular ase of ar onsisteny
A dedution rule h
B an be understood as follow: if all the elements of B are
removed from the global domain, then h does not partiipate in any solution of the CSP
and we an remove it. See for example gure 1. Note that if (x; e) 2 G jfxg does not appear
in any tuple of T , then we have the trivial dedution rule (x; e) ;.
Our formalization is also well suited to inlude weaker ar onsisteny operators. In
GNU-Prolog, a full ar onsisteny operator r of type (fyg; fxg) uses the whole domain
of y, whereas, a partial ar onsisteny redution operator only uses its lower and upper
bounds. In that ase, we need two sets of dedution rules Rmax and Rmin , one for eah
bound. Then, for d G , re(d) = f(x; e) j 9B(x;e) d; (x; e) B(x;e) 2 (Rmax [ Rmin )g.
Note that there exists two rules with the head (x; e), one for the upper bound in Rmax
and one for the lower bound in Rmin .
Example 8 Partial Ar Consisteny in GNU-Prolog
Let us onsider the onstraint \x #= y+" in GNU-Prolog where x, y are variables and
a onstant.
This onstraint is implemented by two loal onsisteny operators: r1
of type (fyg; fxg) and r2 of type (fxg; fyg). In GNU-Prolog, r1 is dened by the rule
x in min(y)+..max(y)+.
r
e1 (d) = f(x; e) j 9B(x;e) d; (x; e) B(x;e) 2 (Rmax [ Rmin )g with:
r2
Rmax = f( ) f( ) j + g j ( ) 2 G jfxg g and
Rmin = f( ) f( ) j + g j ( ) 2 G jfxg g.
of type (f g f g) is dened in the same way by the rule y in
x ;
x; e
y; f
f
e
x; e
x; e
y; f
f
e
x; e
y
min(x)-..max(x)-.
In the framework of hyper-ar onsisteny, the tuples may ontain more than two
variables. For a onstraint 2 C and a variable x 2 var (), if one value of eah tuple
ontaining (x; e) has disappeared of the global domain, then (x; e) an be removed from
the global domain. For (x; e), we have as muh dedution rules as possibilities to take one
element (exept (x; e)) in eah tuple of T ontaining (x; e).
10
Example 9 Hyper-ar Consisteny in GNU-Prolog
Let us onsider the onstraint \x #=# y+z" in GNU-Prolog.
Let G = f(x; 3); (y; 1); (y; 2); (z; 1); (z; 2)g. The onstraint is implemented by three loal
onsisteny rules r1 , r2 and r3 . Let us onsider r1 of type (fy; z g; fxg). r1 is dened by:
r
e1 (d) = f(x; e) j 9B(x;e) d; (x; e) B(x;e) 2 Rg.
We an eliminate (x; 3) from d if for eah tuple ontaining (x; 3), one value is removed from
d. There exists two tuples ontaining (x; 3): f(x; 3); (y; 1); (z; 2)g and f(x; 3); (y; 2); (z; 1)g.
So, we have:
(y; 1) 62 d ^ (y; 2) 62 d ) (x; 3) 62 r1 (d);
(y; 1) 62 d ^ (z; 1) 62 d ) (x; 3) 62 r1 (d);
(y; 2) 62 d ^ (z; 2) 62 d ) (x; 3) 62 r1 (d);
(z; 1) 62 d ^ (z; 2) 62 d ) (x; 3) 62 r1 (d);
Then, R ontains the four dedution rules:
(x; 3)
(x; 3)
(x; 3)
(x; 3)
f(
f(
f(
f(
y;
y;
y;
z;
1); (y; 2)g
1); (z; 1)g
2); (z; 2)g
1); (z; 2)g
In this setion, we have onsidered a dual view of domain redution. In this framework,
we have introdued dedution rules. These rules explain the withdrawal of a value by the
withdrawal of other values. In the next setion, we onstrut trees with these rules, in
order to have a omplete explanation of a value withdrawal assoiated to an iteration.
5
Value withdrawal explanations
Sometimes, when a domain beomes empty or just when a value is removed from a domain,
the user wants an explanation of this phenomenon [2, 11℄. The ase of failure is the
partiular ase where all the values are removed. It is the reason why the basi event here
will be a value withdrawal. Let us onsider a haoti iteration, and let us assume that at
a step a value is removed from the domain of a variable. In general, all the operators used
from the beginning of the iteration are not neessary to explain the value withdrawal. It
is possible to explain the value withdrawal by a subset of these operators suh that every
haoti iteration using this subset of operators removes the onsidered value. We assoiate
a set of proof trees to a value withdrawal during a haoti iteration. We have two notions
of explanation for a value withdrawal. The rst one is a set of loal onsisteny operators
responsible of this withdrawal, the seond one, more preise is based on the proof trees.
We reall here the denition of proof trees, then we dedue the explanation set and provide
some important properties for our explanations.
First, we use the dedution rules in order to build proof trees. We onsider the set of
all the dedution rules for all the loal onsisteny operators r 2 R: let R = [r2R Rr .
11
We use the following notations: ons(h; T ) is a tree, h is the label of its root and T
the set of its sub-trees. We denote by root(t) the label of the root of a tree t. We reall
the denition of a proof tree [1℄.
Denition 10 A proof tree with respet to
proof tree if
f
h
( ) j t 2 T g 2 R and
root t
R is indutively dened by:
T
ons(h; T ) is a
is a set of proof trees with respet to R.
Our set of dedution rules is not omplete: we must take the initial domain into
aount. If we ompute a downward losure from the whole global domain G , then its
omplementary is the empty set. In this ase, R is omplete. But if we ompute a
downward losure from a domain d G , then its dual upward losure starts with d. We
need fats in order to diretly inlude the elements of d. Let Rd = R [ fh ; j h 2 dg.
Next lemma ensures that, with this set of dedution rules, we an build proof trees for
eah element of C L " (d; Re).
Lemma 4
CL
#(
d; R
) is the set of the roots of proof trees with respet to
Rd .
Proof. straightforward
It is important to note that some proof trees do not orrespond to any haoti iteration.
We are interested in the proof trees orresponding to a haoti iteration.
Example 10 Continuation of example 1
Let us onsider the CSP dened in example 1. Six redution rules are assoiated to the
onstraints of the CSP:
r1
of type (fyg; fxg) and r2 of type (fxg; fyg) for x < y.
r3
of type (fz g; fyg) and r4 of type (fyg; fz g) for y < z .
r5
of type (fz g; fxg) and r6 of type (fxg; fz g) for z < x.
Figure 2 shows three dierent proof trees rooted by (x; 0). For example, the rst one
says: (x; 0) is removed from the global domain beause (y; 1) and (y; 2) are removed from
the global domain. (y; 1) is removed from the global domain beause (z; 2) is removed
from the global domain and so on . . . The rst and third proof trees orrespond to some
haoti iterations. But the seond one does not orrespond to any (beause (x; 0) ould
not disappear twie).
We provide now the denition of an explanation set.
Denition 11 We all an explanation set for
E
R
suh that
h
62
CL
#(
d; E
).
h
2G
a set of loal onsisteny operators
From now on, we onsider a xed haoti iteration d = d0 ; d1 ; : : : ; di ; : : : suh that
= C L # (d; R). In this ontext, to eah h 2 d n d! , we an assoiate one and only one
integer i 1 suh that h 2 di 1 n di . This integer is the step in the haoti iteration where
h is removed of the global domain.
!
d
12
(x; 0)
(y; 1)
(x; 0)
(y; 2)
(y; 1)
(z; 2)
(y; 2)
(x; 0)
(x; 0)
Figure 2: Proof trees for (x; 0)
Denition 12 If h 2 d n d! , we denote by step(h), the integer i 1 suh that h 2 di
If
h
62
d
then
( ) = 0.
1
n
d
i.
step h
We know that when an element is removed, there exists a proof tree rooted by this
element. This proof tree uses a set of loal onsisteny operators. These operators are
responsible of this value withdrawal. We give a notation for suh a set in the following
denition.
Denition 13 Let t a proof tree. We denote by
operators:
f
r
step((x;e))
j(
) has an ourrene in
x; e
( ) the set of loal onsisteny
expl set t
t
g.
Note that an explanation set is independent of any haoti iteration in the sense of:
if an explanation set is responsible of a value withdrawal then whatever is the haoti
iteration used, this set of operators will always remove this element.
Theorem 1 If t is a proof tree, then expl
( ) is an explanation set for
set t
( ).
root t
Proof. By lemma 4.
We have dened explanation sets whih are independent of the omputation. So, when
a value is removed during a omputation, we are able to obtain a set loal onsisteny
operators responsible of this removal and thus a set of onstraints linked to these operators.
This an be useful for failure analysis.
But we are interested in an other problem whih is the debugging of onstraint programs. In this framework, it is useful to have more aurate knowledge than sets of
operators. So, the struture of proof trees whih ontains a notion of ausality for the
removals, provides us more information.
In order to ompute inrementaly the explanations from a haoti iteration, we dene
the set of proof trees S i whih an be onstruted at a step i 2 IN of a haoti iteration.
Obviously, before any omputation, it only ontains the trees without sub-trees rooted by
the elements whih are not in the initial domain. At eah step, we onstrut the new trees
with the trees of the previous steps and the loal onsisteny operator used at this step.
More formally:
13
Denition 14 Let the family (S i )i2IN dened by:
S
S
0
= fons(h; ;) j h 62 dg,
i+1
= S i [ fons(h; T ) j h 2 di ; T
Lemma 5
f
f
i
S ;h
( ) j t 2 T g 2 Rri+1 g.
root t
( ) j t 2 S i g = di .
root t
Proof. By indution on i: S 0 obviously heks this property.
We suppose froot(t) j t 2 S i g = di and we prove
1. froot(t) j t 2 S i+1 g di+1 . Let h the root of t suh that t 2 S i+1 . There
exists two ases:
t 2 S i, then h 2 di, then h 2 di+1 beause di di+1 .
t 62 S i . There exists h B 2 Rri+1 ; h 2 di and 8b 2 B ; b =
i
i
i+1 (di ) [ di = di+1 .
root(tb ); tb 2 S . So, b 2 d , thus h 2 r
2. di+1 froot(t) j t 2 S i+1 g. Let h 2 di+1 . There exists two ases:
h 2 di, then h 2 froot(t) j t 2 S ig, then h 2 froot(t) j t 2 S i+1g.
h 2 di , then 9h B 2 Rri+1 and 8b 2 B ; b 2 di. That is B =
froot(t) j t 2 T g and ons(h; T ) 2 S i+1, that is h 2 froot(t) j t 2
i+1 g.
S
The previous lemma is reformulated in the following orollary whih ensures that eah
element removed from d during a haoti iteration is the root of a tree of [i2IN S i .
Corollary 1
( ) j t 2 [i2IN S i g = C L # (d; R).
f
f
root t
( ) j t 2 [i2IN S i g =
=
=
=
root t
Proof.
[ i2 f ( ) j 2 i g
[i2 i by lemma 5
IN root t
d
!
t
S
IN d
CL
#(
d; R
)
(x; 0; r1 )
(y; 1; r3 )
(y; 2; r3 )
(z; 2; r6 )
Figure 3: Explanation tree for (x; 0)
From a proof tree, we an obtain the loal onsisteny operators used with the funtion
step. It ould be interesting to have this information diretly in the tree. So, we onsider
an explanation tree as a proof tree suh that, to eah element h of the tree, we add the
14
loal onsisteny operator orresponding to step(h). For example, the rst proof tree of
Figure 2 provides the explanation tree of Figure 3. The orresponding explanation set is
fr1 ; r3 ; r6 g.
In this last setion, we have provided the theoretial foundations of value withdrawal
explanations. We will use them to explain failures and error diagnosis but this is not in
the sope of this report.
6
Conlusion
This report has given the theoretial model for the solvers on nite domains by domain
redution. This model is language independent and an be applied to eah platform of the
partners: GNU-Prolog, CHIP and PaLM. This model takes several onsistenies (partial
and full hyper-ar onsisteny of GNU-Prolog for example) into aount and is well suited
to dene explanations and traes.
This model rests on redution operators and haoti iteration. Redution operators
are dened from the onstraint and the onsisteny used. These operators are applied
among a haoti iteration whih ensures to take all of them into aount. The order of
invoation of the operators depends on the strategy used by the solver and is out of the
sope of this report.
In the fourth part of the report, we were motivated by the explanations, that is to
be able to answer to the question: Why this value does not appear in any solution ? So,
we did not have to onsider the global domain but its omplementary, that is the set of
removed values. A dedution rule is able to explain the propagation mehanism. It says
us: these values are not in the urrent global domain, so this one an be removed too.
The linking of these rules denes proof trees. These trees explain the withdrawal of a
value from the beginning of the omputation to the value withdrawal. Only the elements
responsible of the value withdrawal appears in these trees. We have dened explanations
sets, that is sets of operators responsible of a value withdrawal, whih an be suÆient for
several appliations.
Narrowing and labeling are interleaved during a resolution. So the next step of our
work will inlude the labeling stage in this model. Finally we will take the language into
aount.
This report has beneted from works and disussions with EMN.
Referenes
[1℄ P. Azel. An introdution to indutive denitions. In J. Barwise, editor, Handbook
of Mathematial Logi, volume 90 of Studies in Logi and the Foundations of Mathematis, hapter C.7, pages 739{782. North-Holland Publishing Company, 1977.
[2℄ A. Aggoun, F. Bueno, M. Carro, P. Deransart, M. Fabris, W. Drabent, G. Ferrand, M. Hermenegildo, C. Lai, J. Lloyd, J. Maluszynski, G. Puebla, and A. Tessier.
CP Debugging Needs and Tools. In M. Kamkar, editor, International Workshop on
Automated Debugging, volume 2 of Linkoping Eletroni Artiles in Computer and
Information Siene, 1997.
15
[3℄ K. R. Apt. The Essene of Constraint Propagation. Theorial Computer Siene,
221(1{2):179{210, 1999.
[4℄ K. R. Apt. The role of ommutativity in onstraint propagation algorithms. ACM
TOPLAS, 22(6):1002{1034, 2000.
[5℄ F. Benhamou. Heterogeneous Constraint Solving. In M. Hanus and M. RofrguezArtalejo, editors, International Conferene on Algebrai and Logi Programming, volume 1139 of Leture Notes in Computer Siene, pages 62{76. Springer-Verlag, 1996.
[6℄ P. Codognet and D. Diaz. Compiling Constraints in lp(FD). Journal of Logi
Programming, 27(3):185{226, 1996.
[7℄ P. Cousot and R. Cousot. Automati synthesis of optimal invariant assertions mathematial foundation. In Symposium on Artiial Intelligene and Programming Languages, volume 12(8) of ACM SIGPLAN Not., pages 1{12, 1977.
[8℄ G. Ferrand and A. Tessier. Positive and Negative Diagnosis for Constraint Logi
Programs in terms of Proof Skeletons. In M. Kamkar, editor, International Workshop
on Automated Debugging, volume 2 of Linkoping Eletroni Artiles in Computer and
Information Siene, 1997.
[9℄ F. Goualard and F. Benhamou. A visualization tool for onstraint program debugging. In International Conferene on Automated Software Engineering, pages 110{117.
IEEE Computer Soiety Press, 1999.
[10℄ C. Gueret, N. Jussien, and C. Prins. Using intelligent baktraking to improve branh
and bound methods: an appliation to Open-Shop problems. European Journal of
Operational Researh, 2000.
[11℄ N. Jussien. Relaxation de Contraintes pour les Problemes dynamiques. PhD thesis,
Universite de Rennes 1, 1997.
[12℄ K. Marriott and P. J. Stukey. Programming with Constraints: An Introdution. MIT
Press, 1998.
[13℄ M. Meier. Debugging onstraint programs. In U. Montanari and F. Rossi, editors,
International Conferene on Priniples and Pratie of Constraint Programming, volume 976 of Leture Notes in Computer Siene, pages 204{221. Springer-Verlag, 1995.
[14℄ U. Montanari and F. Rossi. Constraint relaxation may be perfet. Artiial Intelligene, 48:143{170, 1991.
[15℄ A. Tessier and G. Ferrand. Delarative Diagnosis in the CLP sheme. In P. Deransart,
M. Hermenegildo, and J. Maluszynski, editors, Analysis and Visualisation Tools for
Constraint Programming, hapter 5. Springer-Verlag, 2000. (to appear).
[16℄ E. Tsang. Foundations of Constraint Satisfation. Aademi Press, 1993.
[17℄ M. H. Van Emden. Value Constraints in the CLP sheme. In International Logi
Programming Symposium, post-onferene workshop on Interval Constraints, 1995.
16
[18℄ P. Van Hentenryk. Constraint Satisfation in Logi Programming. Logi Programming. MIT Press, 1989.
17
Download