Python bindings to the Choco Constraint Programming solver
Project description
PyChoco
Python bindings for the Choco Constraint programming solver (https://choco-solver.org/).
Choco-solver is an open-source Java library for Constraint Programming (see https://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 a native-build of 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 with GraalVM native-image tool.
We heavily relied on JGraphT Python bindings source code to understand how such a thing could be achieved, so many thanks to JGraphT authors!
Installation
We 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 pychoco
Documentation
If you do not have any knowledge about Constraint Programming (CP) and Choco-solver, you can have a look at https://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 at https://pychoco.readthedocs.io/ .
Quickstart
Pychoco'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:
from pychoco import Model
model = 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() for i in intvars]))
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 ? False
Build from source
The following system dependencies are required to build PyChco from sources:
- GraalVM >= 22 (see https://www.graalvm.org/)
- Native Image component for GraalVM (see https://www.graalvm.org/22.1/reference-manual/native-image/)
- Apache Maven (see https://maven.apache.org/)
- Python >= 3.6 (see https://www.python.org/)
- SWIG >= 3 (see https://www.swig.org/)
Once these dependencies are satisfied, clone the current repository:
git clone --recurse-submodules https://github.com/chocoteam/pychoco.git
The --recurse-submodules
is necessary as the choco-solver-capi
is a separate git project included
as a submodule (see https://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_HOME
environment variable is pointing to GraalVM, and from the cloned repository
execute the following command:
sh build.sh
This 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à !
Citation
Coming soon.
Getting help or contribute
If you have any questions about using the library, suggestions for improvements, or if you detect a bug, please open an issue.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pychoco-0.1.2-cp311-cp311-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a90fcce96c26410fcfa80d721caa426df0e9b1eec2cabfde2532679e30c3871 |
|
MD5 | 2d617d5fc17f8c9a3f63be15f07384e9 |
|
BLAKE2b-256 | 63913400d2183ac6931e1c81952a188457206609a5ef60bf7f799ff3808d6119 |
Hashes for pychoco-0.1.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9762211fb9691655400f3fa73d0d769f9f9b796555c5da89cf9175056bfed496 |
|
MD5 | 975d6658b0336cc9d11a58a9ffa0e559 |
|
BLAKE2b-256 | f1f93587a811c1585b4b5b2247349fef95ba3e9d86c0c5362829a1e7277e442b |
Hashes for pychoco-0.1.2-cp310-cp310-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf95495f344bcbc64e409e7ec1b7c66414397f63318722d3dadefe05394f965b |
|
MD5 | 3f65ca8fa2a1da730dc24aea3752e8b1 |
|
BLAKE2b-256 | 4cb3eac324962744266c73507e2f2d3907d41e02a8359ba861e2f148f48d3c43 |
Hashes for pychoco-0.1.2-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7eda53d537a964cfbfbf30525774af39cff59fd92cc7b1eff7dcff60aa5fa2 |
|
MD5 | 426b4b382a81ca39c9b081b9258668ba |
|
BLAKE2b-256 | 4d02ed9f6beea6cd64cda34a70afd03c3c04f5b79b17341eba09a4e835ac6e2b |
Hashes for pychoco-0.1.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 972779e980e80c6683bf342e407309a0f41c63b80655a3820c46c05454796b21 |
|
MD5 | f2ed819cd65df5d02c42ebea8315b7ef |
|
BLAKE2b-256 | e91d2dcb436d0c497ee8ed1374830a55b4ad13d03d0d4b9ed81fff32084d8318 |
Hashes for pychoco-0.1.2-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70e818d6737da09e379216cf20cbe9318af6a06979e98dbc7cf13a9c469ae6bb |
|
MD5 | b75c0938b6cba9552d9574a4a2572fcd |
|
BLAKE2b-256 | 15b2a2cd43e12165bc0de39cbe383d5214d2814b7d730a83d4ce57bc9b68de70 |
Hashes for pychoco-0.1.2-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b58decdc5cbe3629049286119f08ad66f3fe7b261c3989d837b3183f5ce255e |
|
MD5 | fe7e7cdb4566f70a93bb05ee066d4481 |
|
BLAKE2b-256 | 32c836d435a675553a642dc77178a90c23235246aa9c725c5ac9aa43b2a03ae5 |
Hashes for pychoco-0.1.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e69edbf8ded16a26ddd7c3d22a79f76f3a3be3897b51e455e494235999f48a86 |
|
MD5 | 9ad964066f14a580f57e4348636080b6 |
|
BLAKE2b-256 | 6d3033d84b46dba3d8b2699b3fc23fdaa8ddc1e0e55ef8df34f979d8395f5d13 |
Hashes for pychoco-0.1.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b139240e8b797092d19cc1af5ee432f66b7db9c813f248475689f557bba9b66b |
|
MD5 | cac0ade6ba49fdaf2acfd5b6686d3e65 |
|
BLAKE2b-256 | e2018978bd0d5c038bb8c58b04c1e82b1b7f65d938a0518d8c8088acceac43af |
Hashes for pychoco-0.1.2-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f043ade95fb70e86d4c7e74c7a9b8df08c49091944fecee6dc861c96879e79d5 |
|
MD5 | e33783feeb5a2466928bfc33ae5bac8d |
|
BLAKE2b-256 | b3037b60a1f9b624fb3cd5580a68923fd9a9778230f14f263ec8b4b5de2f81a5 |
Hashes for pychoco-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | decd8671fbe20bce79381e8f20234d42b25c6e768b2098ff0e11b0f7820fc00d |
|
MD5 | 33fd96e42d02002d901b4affe2174d3a |
|
BLAKE2b-256 | b77ec6f6b1bada23703f1bd19b185a02458e690eeea7d160c58cf083d92d65d7 |
Hashes for pychoco-0.1.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86a1414a903ce29c0e3fb1a1aa088cdd83c375187d00ef9e633947c3fcb9e134 |
|
MD5 | 72a405998c99712faf179a47844c3c04 |
|
BLAKE2b-256 | a2d7dbd9346e90d9252cebc9e32eb91560e75080c0468612222a1f952dd74742 |
Hashes for pychoco-0.1.2-cp37-cp37m-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e3d92340304630376ecfeaaffa0d0236be3dcf320a65409584aec8d581c58ad |
|
MD5 | e7f723348bb9bb6d4ab3c1c0bc2a2876 |
|
BLAKE2b-256 | af4e7221aadb00ecbce279664e3da4c8dc54a51c34b47b3cd9afecff1d31a624 |
Hashes for pychoco-0.1.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5359a655a783d6a12a79f2fc6bb1d4790d289b52d694ae5c957efb785da29f2a |
|
MD5 | 6aadf1cbb56d7a67f5a7d6be66cfffb4 |
|
BLAKE2b-256 | 2ec004f118cb14a9846cf3797be46e5512329d17e6c0ec68c31ef64b9126013d |
Hashes for pychoco-0.1.2-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4331d220a6361024ef18c90fe8d7985711a66bdab8568bb1f618a309cc3ecb74 |
|
MD5 | 7dac9e595ec8c8dec5673ec91bf1ff97 |
|
BLAKE2b-256 | f75e3727385586100b3a98b16def016303f22dec337e8f66e0d68c7977e4bde0 |
Hashes for pychoco-0.1.2-cp36-cp36m-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bac6d1c6accb2b0ad7f97d9c43d593f585efdcbf2807fa0a499ebfb157a62788 |
|
MD5 | 3d1b1398def2f0d64be36ade3f8055b3 |
|
BLAKE2b-256 | 8a03108b4462cd97930a48d97487cc972da8973f713cfda18794ac2f7d2c5e36 |