Extra solver backends for pycsp3 (OR-Tools, IBM CPO, Z3, Glasgow, Pumpkin)
Project description
pycsp3-solvers-extra
Extension library that adds extra solver backends to pycsp3.
Supported Solvers
- OR-Tools CP-SAT - Google's constraint programming solver
- IBM DOcplex CP Optimizer - IBM's CP solver (requires CPLEX Studio)
- Z3 - Microsoft's SMT solver with optimization support
- Glasgow Constraint Solver - CP solver with proof logging support
- Pumpkin - Lazy clause generation CP solver written in Rust
Installation
pip install pycsp3-solvers-extra
Install with specific solver backends:
# Install with OR-Tools
pip install pycsp3-solvers-extra[ortools]
# Install with Z3
pip install pycsp3-solvers-extra[z3]
# Install with CPO (requires IBM CPLEX Studio installed separately)
pip install pycsp3-solvers-extra[cpo]
# Install with Glasgow Constraint Solver
pip install pycsp3-solvers-extra[gcs]
# Install with Pumpkin
pip install pycsp3-solvers-extra[pumpkin]
# Install all backends
pip install pycsp3-solvers-extra[all]
Dependencies
pycsp3- base constraint modeling libraryortools- for OR-Tools backendz3-solver- for Z3 backenddocplex- for CPO backend (requires IBM CPLEX Studio installed separately)gcspy- for Glasgow Constraint Solver backendpumpkin-solver- for Pumpkin backend
Usage
from pycsp3 import *
from pycsp3_solvers_extra import solve
# Define your model
x = VarArray(size=3, dom=range(1, 10))
satisfy(AllDifferent(x))
minimize(Sum(x))
# Solve with OR-Tools
status = solve(solver="ortools")
# Or solve with Z3
status = solve(solver="z3")
# Or solve with CPO
status = solve(solver="cpo")
# Or solve with Glasgow Constraint Solver
status = solve(solver="gcs")
# Or solve with Pumpkin
status = solve(solver="pumpkin")
# Of course, you still can use the native supported pycsp3 solvers as well ('ace', 'choco')
status = solve(solver="ace")
# Access solution values
print([v.value for v in x])
Warm Start (Solution Hints)
Provide hints from a previous solution to guide the solver search:
from pycsp3 import *
from pycsp3_solvers_extra import solve
x = VarArray(size=4, dom=range(10))
satisfy(AllDifferent(x))
# Provide hints as {var_id: value}
hints = {'x[0]': 5, 'x[1]': 2, 'x[2]': 8, 'x[3]': 1}
status = solve(solver='ortools', hints=hints)
Warm start is supported by OR-Tools, CPO, and ACE/Choco. Z3, GCS, and Pumpkin do not support hints natively.
Loading XCSP3 instances
from pycsp3 import clear, solution
from pycsp3_solvers_extra import load, solve
clear()
load("path/to/instance.xml.lzma") # or .xml
status = solve(solver="ortools", time_limit=10)
print(status)
print(solution())
API
solve(
solver="ortools", # "ortools", "z3", "cpo", "gcs", "pumpkin", "ace", or "choco"
time_limit=None, # seconds
sols=None, # number of solutions to find
verbose=0, # verbosity level (0-2)
options="", # solver-specific options
hints=None, # warm start hints as {var_id: value}
output_dir=None # directory for generated XCSP3/log files (defaults to temp)
)
Returns TypeStatus.SAT, TypeStatus.OPTIMUM, TypeStatus.UNSAT, or TypeStatus.UNKNOWN.
Examples
See the examples/ directory:
python examples/send_more_money.py --solvers ortools z3 cpo
python examples/solve_xcsp.py path/to/instance.xml.lzma --solver z3 --time-limit 10
python examples/solve_xcsp.py path/to/instance.xml.lzma --solver ace --options="-positive=CT -sts"
Running Tests
pytest tests/ -v
License
This project is licensed under the MIT License.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycsp3_solvers_extra-0.5.0.tar.gz.
File metadata
- Download URL: pycsp3_solvers_extra-0.5.0.tar.gz
- Upload date:
- Size: 67.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7075e85d4392aa0caeb5952f574b835f162e7e630bfe79c2ea4feb45917730
|
|
| MD5 |
c19239f9831db31e663c1d3bca6fe76b
|
|
| BLAKE2b-256 |
51762bed839318f1558a971b093c2ce06408add2c652ad0a4ee16734d98e2a38
|
Provenance
The following attestation bundles were made for pycsp3_solvers_extra-0.5.0.tar.gz:
Publisher:
publish.yml on sohaibafifi/pycsp3-solvers-extra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycsp3_solvers_extra-0.5.0.tar.gz -
Subject digest:
ba7075e85d4392aa0caeb5952f574b835f162e7e630bfe79c2ea4feb45917730 - Sigstore transparency entry: 854510494
- Sigstore integration time:
-
Permalink:
sohaibafifi/pycsp3-solvers-extra@a43776700ea1c2f35a3b96aeab3732e49aa5dd9b -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/sohaibafifi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a43776700ea1c2f35a3b96aeab3732e49aa5dd9b -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycsp3_solvers_extra-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pycsp3_solvers_extra-0.5.0-py3-none-any.whl
- Upload date:
- Size: 68.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1badef8326e4c1aaed371e2db6d0cfacfedefc0bdc54dc400d94c2ef409c100f
|
|
| MD5 |
c6701ee9c06e0a0073e92f66da84f7e8
|
|
| BLAKE2b-256 |
f9479827b1688b8052d655e7473fac73018dd72f6a7eaf420ef9325387198f9a
|
Provenance
The following attestation bundles were made for pycsp3_solvers_extra-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on sohaibafifi/pycsp3-solvers-extra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycsp3_solvers_extra-0.5.0-py3-none-any.whl -
Subject digest:
1badef8326e4c1aaed371e2db6d0cfacfedefc0bdc54dc400d94c2ef409c100f - Sigstore transparency entry: 854510514
- Sigstore integration time:
-
Permalink:
sohaibafifi/pycsp3-solvers-extra@a43776700ea1c2f35a3b96aeab3732e49aa5dd9b -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/sohaibafifi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a43776700ea1c2f35a3b96aeab3732e49aa5dd9b -
Trigger Event:
push
-
Statement type: