On Testing Constraint Programs
On Testing Constraint Programs
1 Introduction
8
contraintes/OADymPPaC/
On Testing Constraint Programs 3
sequencing problem. It was also used to assess the conformity for small instances
of the problem.
The rest of the paper is organized as follows: Sec. ?? illustrates our testing
framework on a simple case in order to show a typical non-conformity case. Sec.
?? gives the definition of conformity relations required in the framework. In
Sec. ??, the testing process we derive from these definitions is introduced and
illustrated on a simple example. Sec. ?? presents the CPTEST tool and details
our experimental evaluation. Finally, Sec. ?? concludes the paper and draws
some perspectives to this work.
2 An illustrative example
Let us illustrate some of the refinement techniques on the classical problem
of the Golomb rulers, which has various applications in fields such as Radio
communications or X-Ray crystallography.
A Golomb ruler [?] is a set of m marks 0 = x1 < x2 < ... < xm such as
m(m − 1)/2 distances {xj − xi | 1 ≤ i < j ≤ m} are distinct. A ruler is of
order m if it contains m marks, and it is of length xm . The goal is to find a
ruler of order m with minimal length (minimize xm ). A declarative model of
this problem is given in part A of Fig.?? while part B presents a refined and
4 Nadjib Lazaar, Arnaud Gotlieb, Yahia Lebbah
improved model. It is easy to convince a human that model A actually solves the
Golomb rulers problem, but this is much more difficult for model B. Indeed, model
B uses a matrix as data structure (d[indexes]), statically breaks symmetries
(cc6), it contains redundant and surrogate constraints (cc7,cc8,cc9) and global
constraints (allDifferent). In this paper, we address the fundamental question
of revealing non-conformities in between the constraint program under test B and
the model-oracle A. Testing B before using it on large instances of the problem
(when m > 15) is highly desirable as computing the global minimum of the
problem for these instances may require computation time greater than a week.
Note that B is syntactically correct and provides correct Golomb rulers for small
values of m. Our testing framework tries to find an instantiation of the variables
that satisfies the constraints of B and violates at least one constraint of A. This
testing process is detailed in section ??. With m = 8, our CPTEST framework
computes x = [0 1 3 6 10 26 27 28] in less than 6sec on a standard machine,
indicating that B does not conform A and then contains a fault. Indeed, x is not
a Golomb ruler as 27 − 26 = 1 − 0 = 1. In fact, this non-conformity can easily
be tackled by removing the comment on constraint cc5 in part B. Doing so;
CPTEST provides a conformity certificate saying that the CP program actually
computes the global minimum in 10034.69sec (about 3hours). However, note that
this certificate is only valid for m = 8. Note also that our framework can handle
non-conformities of the Golomb rulers where the global minimum requirement
is relaxed in order to deal with larger instances (when m > 30).
3.1 Notations
In the rest of the paper, x denotes a vector of variables and (x\xi ) stands for
substituting x by the valuation xi .
A constraint program includes a constraint model Mx (k),
which is a conjunction of constraints Ci (x) over variables x pa-
Model Mx (k) rameterized by k, the parameters vector of the model. Note that
C1 (x)
x may depend on k. For the Golomb rulers, k is the order of the
... ruler while x represents the vector of marks. If k = 3 then one
Cn (x) seeks for a ruler with 3 marks (e.g., x=[0 1 3]) while if k = 4
Solve() one seeks for a ruler with 4 marks (e.g., x=[0 1 4 6]). Solve()
is a generic procedure representing either the call to a constraint
solver in the case of constraint satisfaction problem or the call to
an optimization procedure. In this latter case, we note f the cost function (for
the sake of clarity, f will be a minimization function but maximization problems
can be tackled as well). We consider that k belongs to K the set of possible
values of the parameters for which Mx (k) has at least one solution. sol(Mx (k))
denotes the set of solutions of Mx (k) and while P rojy (sol(Mx (k))) expresses the
projection of sol(Mx (k)) on the set y when y ⊆ x. In optimization problems, one
usually starts with feasible solutions ranging in a cost interval [l, u]. Therefore,
On Testing Constraint Programs 5
Definition 1 (confone )
k
P confone M ⇔ P rojx (sol(Pz (k))) 6= ∅ ∧ P rojx (sol(Pz (k))) ⊆ sol(Mx (k))
k
P confone M ⇔ (∀k ∈ K, P confone M)
k
Roughly speaking, for a given instance k, confone asks the solutions of the CPUT
to be included in the solutions of the Model-Oracle. As an example, Fig.??
presents both the sets sol(Mx (k)) noted M and solx (Pz (k)) noted P, where
points in red x raise non-conformities (i.e., faults in the CPUT) while points in
green o are conform w.r.t. the Model–Oracle. Parts (a)(b)(c) of Fig.?? exhibit
non-conformities as solving Pz (k) can lead to solutions which do not satisfy
Mx (k). Part (d) does not exhibit any non-conformity but, as P does not contain
any solution, it does not conform the Model–Oracle for confone . This example
also shows that unsatisfiable models must be considered as non-conform w.r.t.
Model–Oracles, in order to tackle faulty unsatisfiable CPUTs. On the contrary,
part (e) of Fig.?? shows that Pz (k) conforms Mx (k) for confone , as P cannot
contain any non-conformity points.
Fig.?? presents the conformity relation where feasible solutions of the CPUT
are sought in [l0 , u0 ]. BP denotes the set Boundsf 0 ,l0 ,u0 (Px (k)), BM denotes the
set Boundsf,l,u (Mx (k)) while B is the set of global minima of Mx (k). Part (a)
exhibits four non-conformities as these points are not feasible solutions of the
Model–Oracle Mx (k) in [l, u]. For the same reason, Part (b) exhibits two non-
conformities as two feasible solutions of BP with cost in [l0 , u0 ] do not belong to
BM . Part (c) presents also a non-conformity as BP does not contain any feasible
point meaning that the minimization problem cannot find a feasible solution with
cost in [l0 , u0 ]. On the contrary, part (d) shows conformity because solutions of
BP belong to BM . Formaly speaking,
Definition 3 (confbounds )
k
P confbounds M ⇔ P rojx (boundsf 0 ,l0 ,u0 (Pz (k))) 6= ∅
∧ P rojx (boundsf 0 ,l0 ,u0 (Pz (k))) ⊆ boundsf,l,u (Mx (k))
Note that the definition of confbounds does not require that f = f 0 and then cases
where the cost function has been refined can also be handled. This conformity
relation is useful for addressing hard optimization problems as it does not require
the computation of global minima. As a result, it can be used to assess the
correction of models on relaxed instances of the global optimization problems.
We will come back on this advantage in the experimental validation section.
However, for some problems, it may be useful to assess not only the correction
but also the fact that the CPUT actually computes optimal solutions. This can
8 Nadjib Lazaar, Arnaud Gotlieb, Yahia Lebbah
be performed by using the following definition which ensures that the global
optimum belongs to [l0 , u0 ].
Definition 4 (confbest )
k
P confbounds M,
k
P confbest M ⇔ boundsf,−∞,l (Mx (k)) = ∅,
boundsf 0 ,−∞,l0 (Pz (k)) = ∅
4 A CP testing framework
Testing a CPUT w.r.t. an model-oracle requires to select test data. In this con-
text, a test datum defines an instance of the CPUT and a point of the search
space.
Note that evaluating Mk (x) on the test datum (k0 , x0 ) results true when x0 is a
solution of the model and false otherwise. Test execution is realized by evaluating
both Pz\z0 (k0 ) and Mx\x0 (k0 )9 and checks whether the results (either true or
false) are the same. Depending on the selected conformity relation, a test verdict
can be issued. This elementary process can be repeated as long as one wishes,
but it is more interesting to guide the test data generation process by the use
of test purposes. Seeking non-conformities implies finding test data such as the
CPUT is satisfied and the Model–Oracle is violated. This enables to detect faults
in CPUT, and helps the constraint programmer to revisit its refinements. Based
on the selection of a conformity relation, non-conformities can be sought with
the following test purposes:
confbounds Given k and [l0 , u0 ], find a solution to Pz (k) ∧ ¬Ci ∧ f 0 (z) ∈ [l0 , u0 ] ∧
f (x) ∈ [l, u] where f, f 0 are the cost functions of the Model-Oracle Mx (k) and
the CPUT Pz (k). Proving that these constraints are unsatisfiable permits to
k
issue a certificate P confbounds M.
k
confbest Given k, find a solution to (P ¬confbounds M ) ∨ boundsf,−∞,l (Mx (k)) 6=
∅ ∨ boundsf 0 ,−∞,l0 (Pz (k)) 6= ∅. Proving that these constraints are unsatisfi-
k
able permits to issue a conformity certificate P confbest M.
Interestingly, any solution found by the guidance of one of these test purposes
can be stored for further investigations. Indeed, it can be used to debug the
CPUT by looking at the violated constraint and it can also enrich a test set that
will serve to assess the correction of future versions of the CPUT. In addition,
conformity certificates are essential for those who want to convince third-party
certification authorities that their CP programs can be used in critical systems
[?,?]. So, the proposed testing framework has a role to play in various phases of
the constraint program development.
We now propose a simple but generic algorithm for searching non-conformities:
Algorithm 1: one negated(B, {C1 , ...Cn })
Input : B, {C1 , ...Cn } sets of constraints.
Output: conf when {C1 , ...Cn } conform B, ¬conf (+ non-conformity point) otherwise
nc ← ∅
X ← vars(B)
foreach Ci ∈ {C1 , ..., Cn } do
V ← vars(Ci )/X
if V = ∅ then nc ← Solve(B ∧ ¬Ci )
else nc ← Solve(B ∧ ¬P rojX (Ci ))
if nc then return ¬conf (nc)
end
return conf
where Solve(B) denotes the algorithm to find the first solution of the constraints B, vars(B)
denotes the set of variables in B and P rojX (C) denotes the constraint projection on variables X.
Algorithm ?? takes two constraint sets as input and returns either conf
when both sets conform with relation confone or ¬conf (non-conformity point)
where a non-conformity point has been found. Note that the other conformity
relations can easily be implemented using this algorithm just by adjusting the
call parameters. Special care has to be taken when building the negation of a
model. For example, consider a Model-Oracle M with x-y!=x-z; x-y!=y-z;
x-z!=y-z; and a CPUT P with c1: x-y=d1; c2: x-z=d2; c3: y-z=d3; c4:
allDiff(d1,d2,d3);. Here, it is trivial to see that P confall M but if c1 is
selected for negation, M ∧ ¬c1 has solutions as d1 is out of the scope of M.
In the definitions of the conformity relations, these cases were discarded by the
use of projections on the variables of the model-oracle. As computing general
projections is expensive, pragmatic solutions have been found that are discussed
in the experimental section of the paper (Sec.??).
Providing that the underlying constraint solver is sound and complete, this
algorithm is sound as it cannot report conf if there exists a non-conformity
point. Indeed, given k, upon completion of the algorithm the unsatisfiability of
Pz (k) ∧ ¬Mx (k) is demonstrated showing that both models conform with the
10 Nadjib Lazaar, Arnaud Gotlieb, Yahia Lebbah
5 Experimental validation
5.1 Implementation
the time required for finding these non-conformities is acceptable (less than a few
minutes in the worst case). Secondly, this experiment shows that the most prac-
tical conformance relations (i.e., confone and confbounds ) are preferable to the
other ones for efficiency reason. Indeed, for the first three CPUT, these relations
gave results less than 10sec. Note that non-conformities are represented either by
invalid Golomb rulers (e.g., 44−35 = 35−26 = 9 in the CPUT1/confone case) or
by valid Golomb rulers (e.g., CPUT1/confall case). In fact, a valid Golomb ruler
r can be produced when the model-oracle is satisfied by r while the CPUT is re-
futed by r. These non-conformities correspond to cases where the CPUT misses
solutions of the problem. Interestingly, P is shown as being non-conform with the
confAll relation and the non-conformity that is found represent a valid Golomb
ruler (i.e., [0 7 9 12 37 54 58 64]). In fact, recalling that P includes constraints
that break the symmetries, this result was expected. Finally, note that confor-
mity of P when confbest is selected was impossible to assess within the allocated
time (timeout=5 400s). In fact, computing the global minimum of the Golomb
ruler rapidly becomes hard even for small values of m (e.g., CPUT3/confbest ).
Our experimental evaluation also had the goal to check that computing non-
conformities with CPTEST was less hard than computing solutions. For that,
Fig. ?? shows: A) the CPU time required to find a global optimum for instances
of the Golomb rulers (red line) and B) the CPU time required to find non-
conformities with CPTEST with the confbounds conformity relation (blue line).
The search heurisitic used in both cases is the default heuristic of OPL, i.e. depth-
On Testing Constraint Programs 13
first search with restarts, and branch-and-bound for the global optimization
problem. CPTEST can find non-conformities when m < 22 in a reasonable
amount of time because the hard global optimization problem has been relaxed
in a simpler satisfaction problem, in order to deal with larger instances. This is
the essence of the confbounds conformity relation.
Fig. 6. Testing time and solving time comparison on the Golomb rulers.
Confone Confall
10 slots 55 slots 10 slots 55 slots
Non-conf points 4 5 3 6 4 6 5 1 3 2 p1 4 5 4 6 3 6 5 1 3 2 —
Non-conf points 4 6 3 1 5 2 3 5 4 6 p2 5 4 3 5 4 6 2 6 3 1 —
Non-conf points 5 2 3 6 1 4 3 6 4 5 p3 5 4 3 5 4 6 2 6 3 1 —
p1 = 6 5 6 4 5 2 4 4 4 3 5 6 7 6 3 3 3 5 6 4 5 5 2 2 7 3 4 2 5 5 5 4 1 3 4 1 6 4 3 1 5 3 3 6 1 6 7 7 7 2 6 3 1 6 4
p2 = 7 1 6 3 4 6 1 7 3 2 5 1 7 3 5 4 2 6 6 6 4 3 6 5 3 4 4 2 4 6 1 3 7 5 5 2 5 5 3 7 6 3 1 6 4 3 5 4 2 4 6 5 5 4 3
p3 = 4 3 1 5 6 5 5 1 2 4 2 3 6 6 6 3 2 5 2 1 7 4 4 4 3 3 3 5 4 3 6 4 6 6 4 1 7 3 1 5 6 4 2 5 7 6 3 5 5 6 7 4 3 7 5
p4 = 1 3 6 2 5 4 3 5 2 6 4 5 3 4 5 2 6 3 5 4 4 5 3 7 6 4 1 3 6 7 1 7 6 3 1 4 6 7 5 2 6 3 1 7 6 4 5 4 3 5 4 6 2 5 3
bad formulation but it is quickly detected with confone . When confall is selected,
more constraints have to be negated and then our algorithm has to backtrack a
lot, which explains the failure. The non-conformity reached in this case satisfies
the model-oracle and violates CPUT2, so it represents a correct assembly line
that CPUT2 excludes from its solutions. Therefore, we can conclude that CPUT2
adds and removes solutions which make it difficult to detect as non-conform.
6 Conclusion
In this paper, we introduced for the first time a testing framework that is adapted
to standard CP development processes. The framework is built on solid notions
such as conformity relations, oracles and test purposes that are specific to CP. We
also presented CPTEST an implementation of our framework dedicated to the
testing of OPL programs and evaluated it on difficult instances of two well-known
constraint problems, namely the Golomb ruler and car-sequencing problem. Our
experimental evaluation shows that CPTEST can efficiently detect non-trivial
faults in faulty versions of those two problems. A desirable extension of our
framework and tool concerns its application to other more open CP plateforms.
In particular, we would like to apply our conformity relations, oracles and testing
notions to GECODE or CHOCO programs as we could intervene on the core
constraint solver of these systems. Developing notions of test coverage similar
of those that can be found in conventional programming requires instrumenting
the solver, something that was just not possible with the black-box solver of
OPL.
On Testing Constraint Programs 15
Acknowledgment
We are very grateful to Olivier Lhomme who pointed us the problem of out-of-
scope variables. Many thanks also to Michel Rueher, Laurent Granvilliers and
Nicolas Beldiceanu for helpful comments on early presentations.
References
1. H. Collavizza, M. Rueher, and P. Van Hentenryck. Cpbpv: A constraint-
programming framework for bounded program verification. In Proc. of CP2008,
LNCS 5202, pages 327–341, 2008.
2. P. Deransart, M. V. Hermenegildo, and J. Maluszynski, editors. Analysis and
Visualization Tools for Constraint Programming, Constrain Debugging (DiSCiPl
project), volume 1870 of Lecture Notes in Computer Science. Springer, 2000.
3. P. Flener, J. Pearson, M. Agren, Garcia-Avello C., M. Celiktin, and S. Dissing.
Air-traffic complexity resolution in multi-sector planning. Journal of Air Transport
Management, 13(6):323 – 328, 2007.
4. A. Gotlieb. Tcas software verification using constraint programming. The Knowl-
edge Engineering Review, 2009. Accepted for publication.
5. Alan Holland and Barry O’Sullivan. Robust solutions for combinatorial auctions.
In ACM Conference on Electronic Commerce (EC-2005), pages 183–192, 2005.
6. U. Junker and D. Vidal. Air traffic flow management with ilog cp optimizer. In
International Workshop on Constraint Programming for Air Traffic Control and
Management, 2008. 7th EuroControl Innovative Research Workshop and Exhibi-
tion (INO’08).
7. L. Langevine, P. Deransart, M. Ducassé, and E. Jahier. Prototyping clp(fd) tracers:
a trace model and an experimental validation environment. In WLPE, 2001.
8. W. T. Rankin. Optimal golomb rulers: An exhaustive parallel search implementa-
tion. Master’s thesis, Duke University, Durham, 1993.
9. N.V. Sahinidis and M. Twarmalani. Convexification and Global Optimization in
Continuous and Mixed-Integer Nonlinear Programming. Kluwer Academic Pub-
lishers Group, 2002.
10. Pascal Van Hentenryck. The OPL optimization programming language. MIT Press,
1999.
11. Elaine J. Weyuker. On testing non-testable programs. Computer Journal,
25(4):465–470, 1982.
12. Hong Zhu, Patrick A. V. Hall, and John H. R. May. Software unit test coverage
and adequacy. ACM Comput. Surv., 29(4):366–427, 1997.