Package: pychoco
PyChocoPython bindings for the Choco Constraint programming solver (https://choco-solver.org/).Choco-solver is an open-source Java library for Constraint Programming (seehttps://choco-solver.org/).
It comes with many features such as various types of variables, various state-of-the-art constraint,
various search strategies, etc.The PyChoco library uses anative-buildof the original Java Choco-solver library, in the form
of a shared library, which means that it can be used without any JVM. This native-build is created
withGraalVMnative-image tool.We heavily relied onJGraphT Python bindingssource code to
understand how such a thing could be achieved, so many thanks to JGraphT authors!InstallationWe automatically build 64-bit wheels for Python versions 3.6, 3.7, 3.8, 3.9, and 3.10 on Linux, Windows and
MacOSX. They can be directly downloaded from PyPI (https://pypi.org/project/pychoco/) or using pip:pip install pychocoDocumentationIf you do not have any knowledge about Constraint Programming (CP) and Choco-solver, you can have a look athttps://choco-solver.org/tutos/for a quick introduction to CP and to Choco-solver features. For this Python API,
we also provide an API documentation which is available online athttps://pychoco.readthedocs.io/.QuickstartPychoco's API is quite close to Choco's Java API. The first thing to do is to import the
library and create a model object:frompychocoimportModelmodel=Model("My Choco Model")Then, you can use this model object to create variables:intvars=model.intvars(10,0,10)sum_var=model.intvar(0,100)You can also create views from this Model object:b6=model.int_ge_view(intvars[6],6)Create and post (or reify) constraints:model.all_different(intvars).post()model.sum(intvars,"=",sum_var).post()b7=model.arithm(intvars[7],">=",7).reify()Solve your problem:model.get_solver().solve()And retrieve the solution:print("intvars ={}".format([i.get_value()foriinintvars]))print("sum ={}".format(sum_var.get_value()))print("intvar[6] >= 6 ?{}".format(b6.get_value()))print("intvar[7] >= 7 ?{}".format(b7.get_value()))> intvars = [3, 5, 9, 6, 7, 2, 0, 1, 4, 8]
> sum = 45
> intvar[6] >= 6 ? False
> intvar[7] >= 7 ? FalseBuild from sourceThe following system dependencies are required to build PyChco from sources:GraalVM >= 22 (seehttps://www.graalvm.org/)Native Image component for GraalVM (seehttps://www.graalvm.org/22.1/reference-manual/native-image/)Apache Maven (seehttps://maven.apache.org/)Python >= 3.6 (seehttps://www.python.org/)SWIG >= 3 (seehttps://www.swig.org/)Once these dependencies are satisfied, clone the current repository:git clone --recurse-submodules https://github.com/chocoteam/pychoco.gitThe--recurse-submodulesis necessary as thechoco-solver-capiis a separate git project included
as a submodule (seehttps://github.com/chocoteam/choco-solver-capi). It contains all the necessary
to compile Choco-solver as a shared native library using GraalVM native-image.Ensure that the$JAVA_HOMEenvironment variable is pointing to GraalVM, and from the cloned repository
execute the following command:sh build.shThis command will compile Choco-solver into a shared native library and compile the Python bindings
to this native API using SWIG.Finally, run:pip install .And voilà !CitationComing soon.Getting help or contributeIf you have any questions about using the library, suggestions for improvements, or if you
detect a bug, pleaseopen an issue.