<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Solving XCSP problems by using Gecode</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Massimo Morara</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jacopo Mauro</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Maurizio Gabbrielli</string-name>
          <email>gabbri@cs.unibo.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Bologna. morara</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>Gecode is one of the most e cient libraries that can be used for constraint solving. However, using it requires dealing with C++ programming details. On the other hand several formats for representing constraint networks have been proposed. Among them, XCSP has been proposed as a format based on XML which allows us to represent constraints de ned either extensionally or intensionally, permits global constraints and has been the standard format of the international competition of constraint satisfaction problems solvers. In this paper we present a plug-in for solving problems speci ed in XCSP by exploiting the Gecode solver. This is done by dynamically translating constraints into Gecode library calls, thus avoiding the need to interact with C++.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Constraint Programming [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ] has attracted high attention among experts from
many areas because of its potential for solving hard real life problems and
because it is based on a strong theoretical foundation. The success of Constraint
Programming (CP) derives from the fact that on one hand it allows to model a
problem in a simple way and on the other hand it provides an e cient problem
solving algorithms. However, the CP community lacks a standardized
representation of problem instances and this still limits the acceptance of CP by the
business world. One attempt to overcome this problem was taken by the
Association for Constraint Programming with the proposal of Java Speci cation
Request JSR-331 \Constraint Programming API" [
        <xref ref-type="bibr" rid="ref5 ref8">8, 5</xref>
        ]. The goal of this
speci cation is the creation of a powerful API for specifying CP problems. In the
last ve years other approaches focusing on more low level languages emerged.
The aim of these approaches is to de ne a minimal domain dependent language
that supports all the major constraint features and requires, at the same time, a
minimal implementation e ort to be supported by constraint solvers. Two
languages following this goal are worth mentioning: FlatZinc [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] and XCSP [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ].
The former was originally created to be the target language into which a higher
level CSP instance (e.g. a CSP modeled with MiniZinc [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]) is translated. Today
FlatZinc is also used as a low level \lingua franca" for solver evaluation and
testing. For instance, since 2008 FlatZinc has been used in the MiniZinc Challenge
[
        <xref ref-type="bibr" rid="ref14 ref7">7, 14</xref>
        ], a competition where di erent solvers are compared by using a benchmark
of MiniZinc instances that are compiled into FlatZinc.
      </p>
      <p>
        XCSP is a language structurally very similar to FlatZinc. XCSP was de ned
with the purpose of being a unique constraint model that could be used by all
the CP solvers. It was rst proposed in 2005 for the solvers competing in the
International CSP Solver Competition [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], and has then been used in other
contexts and extended. In this paper, we focus on XCSP. In particular, we consider
its current version, i.e. XCSP version 2.1.
      </p>
      <p>
        The need of a standard is also caused by the huge number and diversity
of solvers. Today only few solvers support natively FlatZinc or XCSP.
Unfortunately, Gecode [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], one of the most well known and used solvers, support FlatZinc
only. For this reason we have created x4g, a plug-in that allows us to solve
problems de ned in XCSP by using the Gecode solver. The goal of x4g is twofold.
Firstly, we want to exploit Gecode for solving problems that are speci ed in
XCSP without considering low level implementation details or writing a single
line of code in C++. Secondly, we want to provide a tool that can be used to
evaluate the performances of the Gecode solver with respect to the other entries
of the International Solver Competition. This could be very interesting since,
to the best of our knowledge, the benchmark used in the International Solver
Competition is the biggest available to the CP community.1
      </p>
      <p>In the reset of this paper, we present in Section 2 a brief overview of the
XCSP language and of the Gecode solver. In Section 3 we describe the idea
behind the x4g plug-in. Section 4 concludes by mentioning some directions for
future works.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Background</title>
      <p>An extensive presentation of the XCSP format and the Gecode solver is beyond
the scope of this paper. Here we just give a short overview of XCSP and Gecode.
2.1</p>
      <sec id="sec-2-1">
        <title>XCSP</title>
        <p>XSCP is an extended format to represent constraint networks using XML. The
Extensible Markup Language (XML) is a simple and exible text format playing
an increasingly important role in the exchange of a wide variety of data on the
Web. The objective of the XML representation (in XCSP) is to ease the e ort
required to test and compare di erent algorithms by providing a common testbed
of constraint satisfaction instances. The proposed representation is low-level: for
each instance the domains, variables, relations (if any), predicates (if any) and
constraints are exhaustively de ned. No control ow constructs like\for" cycles
or \if then else" statements can be used.</p>
        <p>Roughly speaking, there exist two variants of this format: a fully-tagged
representation and an abridged representation. The rst one is a full XML,
completely structured representation which is suitable for using generic XML
tools but is quite verbose and tedious to use for a human being. The second
representation is just a shorthand notation of the rst one and it is easier to
read and to write for a human being, but less suitable for generic XML tools.
1 The MiniZinc Challenge has a smaller benchmark of instances and fewer participants
than the International Solver Competition.</p>
        <p>As an example of an XCSP program consider the following one where the
well known \all di erent" constraint is applied to two variables A1 and A2 which
can assume values only in the domain [1; 2].
&lt;domains nbDomains="1"&gt;</p>
        <p>&lt;domain name="d0" nbValues="2"&gt;1..2&lt;/domain&gt;
&lt;/domains&gt;
&lt;variables nbVariables="2"&gt;
&lt;variable name="A1" domain="d0"/&gt;
&lt;variable name="A2" domain="d0"/&gt;
&lt;/variables&gt;
&lt;constraint name="c0" arity="2"
scope="A1 A2"
reference="global:alldifferent"/&gt;
2.2</p>
      </sec>
      <sec id="sec-2-2">
        <title>Gecode</title>
        <p>Gecode (Generic Constraint Development Environment) provides a constraint
solver with state-of-the-art performance while being modular and extensible. It
supports the programming of new propagators, branching strategies, and search
engines. New domains can be programmed at the same level of e ciency as
nite domain and integer set variables that are already prede ned. Furthermore
Gecode is distributed under a very permissive license, it is portable and well
documented, and comes with a complete tutorial. All these features have made
Gecode one of the preferred choices for solving CSPs.</p>
        <p>
          Gecode is written in C++ and supports the FlatZinc format through an
external plug-in that is able to parse a FlatZinc instance and solve it using
Gecode library calls. The use of this plug-in allowed Gecode to participate to
the 2010 MiniZinc challenge [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ], where it won all the tracks of the competition.
3
        </p>
        <p>
          x4g
In principle the translation of XCSP instances into Gecode is similar to the task
performed by the Gecode/FlatZinc plug-in [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ] that parses a FlatZinc instance
and produces an internal data structure (Gecode Space Object) that can be later
used to retrieve the solution of the CSP problem.
        </p>
        <p>
          To use Gecode in order to solve CSPs de ned in XCSP, one could try
implement a XCSP to FlatZinc compiler. However, in order to avoid potential loss
of information, to be more exible and less dependent on the Gecode/FlatZinc
plug-in, we chose to provide a direct translation from XCSP into Gecode. Hence
we have developed x4g; a plug-in that parses an XCSP instance and, for
every constraint de ned within the XCSP le, generates an equivalent number of
Gecode constraints. When all the XCSP constraints are translated into Gecode
constraints, a Gecode Space Object is returned. This object can later be used to
get a solution to the CSP problem by using one of the many prede ned search
strategies provided by Gecode or local search strategies following [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ].2
        </p>
        <p>
          To develop the x4g plug-in we used the XCSP parser provided by the
International CSP competition organizers. This parser, developed in particular
to support the abridged notation, is written in C++ by using the well known
libxml2 libraries [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ]. Unfortunately, the parser supports only a limited number
of global constraints. Therefore, we modi ed it in order to support additional
ones.
        </p>
        <p>The XCSP format is mainly used to specify CSPs but it also supports
extensions to de ne weighted constraints or quanti ers over constraints. x4g was
designed to target only CSPs, hence it does not support these additional features.</p>
        <p>
          XCSP supports only nite domains. Since Gecode supports nite domains
too, the domain encoding from XCSP to Gecode was straightforward. XCSP
provides a construct which allows one to de ne relations over variables. These
could be seen as constraints listing all the admissible values that some variables
can take. XCSP relations are mapped into Gecode by using extensional
constraints. In XSCP the semantics of a relation can also be given by stating all
the non admissible values of the variables (i.e. con icts between variables). We
used inequality constraints for translating these relations into Gecode. Another
construct of XCSP is predicate, a boolean parametric expression that is
considered satis ed if and only if it evaluates to true. The number of parameters
in a predicate is xed and, di erently from relations, predicates allow integer
parameters. The mapping of the predicates was also straightforward because,
with only few exceptions, Gecode has for every predicate an API for posting an
equivalent constraint. As far as global constraints are concerned, XCSP supports
the majority of the global constraints de ned in the Global Constraint Catalog
[
          <xref ref-type="bibr" rid="ref4">4</xref>
          ]. Since in this catalog there are hundreds of global constraints, a full XCSP
support means to provide an encoding for a huge number of global constraints.
This was out of the scope of the project, we have just chosen to support a
subset of the most used global constraints. Currently x4g supports the following
global constraints: alldifferent, among, atleast, atmost, cumulative, diffn,
disjunctive, element, global cardinality, lex less, lex lesseq,
not all equal, weightedSum.3
        </p>
        <p>
          Finally, to give an example of how x4g could be used, we developed a program
that takes as input a XCSP instance and, by using x4g, allows us to nd a
solution by using the deep rst strategy natively implemented in Gecode. Since
the output of this program follows the output rules of the International Solver
Competition, it could be used to let Gecode enter the next International CSP
Competition.
2 Note that the XCSP format speci es only the constraints, the choice of the search
strategy is left to the user.
3 For a precise de nition of these constraints see [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ].
In this paper we described x4g, a plug-in that allows the use of Gecode for
solving a CSP instance de ned using the XCSP format. The source code of x4g
and of the above mentioned program can be found at http://www.cs.unibo.
it/~jmauro/cilc_2011.html.
        </p>
        <p>This work has to be considered as a rst step in the direction of providing a
full translation of XCSP constraints into Gecode constraints. As a future work,
we would like to support more global constraints and to de ne e cient ways of
decomposing them by using Gecode constraints. We also would like to extend
our tool in order to use Gecode for solving the optimization problems that can
be de ned in XCSP exploiting weighted constraints.</p>
        <p>Moreover, we are interested in the development of a FlatZinc/XCSP conveyer
that will allow us to add FlatZinc instances into the benchmarks that could be
used for comparing Gecode with other constraint solvers. Furthermore, with
such a converter it could be also possible to compare the e ciency of our x4g
translation with the one of the Gecode/FlatZinc plug-in.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>1. Fourth International CSP Solver Competition website: http://www.cril. univ-artois.fr/CPAI09/.</mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>2. Gecode/FlatZinc plugin website: http://www.gecode.org/flatzinc.html.</mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <article-title>3. Generic constraint development environment website</article-title>
          : http://www.gecode.org/.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>4. Global Constraint Catalog website: http://www.emn.fr/x-info/sdemasse/gccat.</mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5. JSR 331:
          <article-title>Constraint Programming API website</article-title>
          : http://jcp.org/en/jsr/ summary?id=
          <fpage>331</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>6. libxml2 libraries. Available at: http://xmlsoft.org/.</mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>7. MiniZinc Challenge 2011 website: http://www.g12.csse.unimelb.edu.au/ minizinc/challenge2011/challenge.html.</mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <article-title>Standardization of Constraint Programming website</article-title>
          : http://4c110.ucc.ie/ cpstandards/.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>Ralph</given-names>
            <surname>Becket</surname>
          </string-name>
          .
          <source>Speci cation of FlatZinc. version 1</source>
          .3. Available at http://www. g12.csse.unimelb.edu.au/minizinc/downloads/doc-1.3/flatzinc-spec.pdf.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Ra</surname>
            aele Cipriano, Luca Di Gaspero, and
            <given-names>Agostino</given-names>
          </string-name>
          <string-name>
            <surname>Dovier</surname>
          </string-name>
          .
          <article-title>A Hybrid Solver for Large Neighborhood Search: Mixing Gecode and EasyLocal++</article-title>
          . In Hybrid Metaheuristics, pages
          <volume>141</volume>
          {
          <fpage>155</fpage>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Nicholas</surname>
            <given-names>Nethercote</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Peter J. Stuckey</surname>
            , Ralph Becket,
            <given-names>Sebastian</given-names>
          </string-name>
          <string-name>
            <surname>Brand</surname>
            ,
            <given-names>Gregory J.</given-names>
          </string-name>
          <string-name>
            <surname>Duck</surname>
          </string-name>
          , and Guido Tack.
          <article-title>MiniZinc: Towards a Standard CP Modelling Language</article-title>
          .
          <source>In CP Proceeding</source>
          , pages
          <volume>529</volume>
          {
          <fpage>543</fpage>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <article-title>Organising Committee of the Third International Competition of CSP Solvers. XML Representation of Constraint Networks Format XCSP 2</article-title>
          .1,
          <year>2009</year>
          . Available at http://www.cril.univ-artois.fr/CPAI08/XCSP2_1.pdf.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Francesca</surname>
            <given-names>Rossi</given-names>
          </string-name>
          , Peter van Beek, and Toby Walsh, editors.
          <source>Handbook of Constraint Programming. Elsevier</source>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>Peter J. Stuckey</surname>
            , Ralph Becket, and
            <given-names>Julien</given-names>
          </string-name>
          <string-name>
            <surname>Fischer</surname>
          </string-name>
          .
          <article-title>Philosophy of the MiniZinc challenge</article-title>
          .
          <source>Constraints</source>
          ,
          <volume>15</volume>
          (
          <issue>3</issue>
          ):
          <volume>307</volume>
          {
          <fpage>316</fpage>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>