CPMpy/cpmpy

Constraint Programming and Modeling library in Python, based on numpy, with direct solver access.

What it solves

CPMpy tackles combinatorial problems involving Boolean and integer variables, such as scheduling, resource allocation, and optimization. It provides high-level constraints that are automatically decomposed when a solver does not support them natively, making it easy to express complex problems.

How it works

You define decision variables as numpy arrays, add constraints and an objective, then call solve(). CPMpy translates your model to the chosen solver (CP, ILP, SMT, PB, SAT, etc.) and can compare different solvers. It supports incremental solving, assumption variables, and adding constraints or updating objectives after solving.

Who it's for

Researchers and practitioners in constraint programming, operations research, and machine learning who need a lightweight, well-documented library that integrates with the scientific Python ecosystem (pandas, plotly, Jupyter). It is also used in industry and academic research.

Highlights

  • Solver-agnostic: works with CP, ILP, SMT, PB, and SAT solvers
  • ML-friendly: decision variables are numpy arrays with vectorized operations
  • Incremental solving: assumption variables, adding constraints, updating objectives
  • Extensively tested with a large test suite and fuzz testing
  • Tools for parameter tuning, debugging, explanation generation, and XCSP3 benchmarking
  • Open-source (Apache 2.0) with an active community and contributions welcome

Related

  • Project
  • Project
  • Project
  • Project