Skip to main content

Extra solver backends for pycsp3 (OR-Tools, IBM CPO, Z3, Pumpkin, MiniZinc)

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
  • MiniZinc - Interface to MiniZinc solvers (Gecode, Chuffed, CP-SAT, etc.) (WIP)
  • Pumpkin - Lazy clause generation CP solver written in Rust (WIP)

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 MiniZinc (requires MiniZinc CLI installed separately)
pip install pycsp3-solvers-extra[minizinc]

# Install with Pumpkin
pip install pycsp3-solvers-extra[pumpkin]

# Install all backends
pip install pycsp3-solvers-extra[all]

Dependencies

  • pycsp3 - base constraint modeling library
  • ortools - for OR-Tools backend
  • z3-solver - for Z3 backend
  • docplex - for CPO backend (requires IBM CPLEX Studio installed separately)
  • minizinc - for MiniZinc backend (requires MiniZinc installed separately)
  • pumpkin-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 MiniZinc (auto-detects available solver)
status = solve(solver="minizinc")

# Or specify a MiniZinc solver
status = solve(solver="minizinc/gecode")
status = solve(solver="minizinc/chuffed")

# 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 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", "minizinc", "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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycsp3_solvers_extra-0.7.4.tar.gz (98.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycsp3_solvers_extra-0.7.4-py3-none-any.whl (84.5 kB view details)

Uploaded Python 3

File details

Details for the file pycsp3_solvers_extra-0.7.4.tar.gz.

File metadata

  • Download URL: pycsp3_solvers_extra-0.7.4.tar.gz
  • Upload date:
  • Size: 98.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycsp3_solvers_extra-0.7.4.tar.gz
Algorithm Hash digest
SHA256 10d4192f5a370d8d4f8f0d94e4a6153d4b66a7b52221837a5744044d2361b9ca
MD5 86de511aef1b9615cfad2fea1ca22578
BLAKE2b-256 a5edee6fcef715af3581330aa518c40c04730c391874b596f366ea655ab0760b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycsp3_solvers_extra-0.7.4.tar.gz:

Publisher: publish.yml on sohaibafifi/pycsp3-solvers-extra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycsp3_solvers_extra-0.7.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pycsp3_solvers_extra-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b73f2058c425c4e05c2c76f0d1f3248268e5db72b3440caa3b9ba9a9d43d9008
MD5 ad6b4209870f83b9f9b0aa539a8892ac
BLAKE2b-256 254e3f2434149c50ee156731f5498316ee9c84cd6c928012d8264ca4296a2aa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycsp3_solvers_extra-0.7.4-py3-none-any.whl:

Publisher: publish.yml on sohaibafifi/pycsp3-solvers-extra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page