Constraint-programming backends for Pyomo: a discretization transform plus CP solver interfaces (CP-SAT first).
Project description
pyomo-cp
Constraint-programming backends for Pyomo: a discretization transform plus CP solver interfaces, starting with CP-SAT (OR-Tools).
Pyomo can build and solve disjunctive/logical models via pyomo.gdp, but it can
only solve them by reformulating to MILP/MINLP (big-M, hull) and calling a MIP
solver. pyomo-cp adds the missing path: take the same model and solve it with a
constraint-programming solver, where disjunctions map to native reified
constraints instead of being reformulated.
Status: alpha. Integer models,
pyomo.gdpdisjunctions, logical constraints / Boolean variables, and discretization of continuous variables (anystep) work end-to-end viaSolverFactory('cpsat'). Global constraints are not yet supported. See ROADMAP.md.
Scope
pyomo-cp is a backend framework, not a full CP modelling frontend. It
translates what Pyomo can already express:
- integer and (once discretized) continuous variables,
- linear constraints and a linear objective,
- logical constraints (
BooleanVar/LogicalConstraint), pyomo.gdpdisjunctions.
Global constraints (alldifferent, no_overlap, element, cumulative,
...) are the heart of CP's modelling power, and Pyomo has no vocabulary for
them. Adding one is roadmap, not part of the initial scope.
CP solvers are finite-domain, so continuous variables must be discretized first.
That is an explicit step (TransformationFactory('cp.discretize')), never
automatic, because the integrality assumption is a modelling decision that
changes the problem.
Relationship to pyomo.contrib.cp
Pyomo ships an in-tree constraint-programming module, pyomo.contrib.cp. It is a
different tool for a different job, and the two are complementary:
pyomo.contrib.cp |
this package | |
|---|---|---|
| Role | CP frontend | CP backend |
| Built for | scheduling: IntervalVar, sequence vars, Pulse / step functions, precedence |
solving models Pyomo already expresses — no new constructs |
| Input | a CP model written with the interval API | an existing pyomo.gdp / integer / logical model |
| Continuous variables | none (finite-domain only) | explicit cp.discretize onto a grid |
| Solver | IBM CP Optimizer (commercial, via docplex) |
CP-SAT / OR-Tools (open-source) |
In one line: pyomo.contrib.cp is write an interval/scheduling model and solve
it with CP Optimizer; this package is take a disjunctive/integer model you'd
otherwise reformulate to MILP and solve it (optionally discretized) with CP-SAT.
They overlap only on logical constraints; the paradigm (interval scheduling vs
disjunctive/geometric) and the solver (commercial vs open) otherwise differ.
Install
pip install "pyomo-cp[cpsat]" # includes OR-Tools for the CP-SAT backend
Usage
import pyomo.environ as pyo
from pyomo.gdp import Disjunct, Disjunction
import pyomo_cp # registers cp.discretize and the cpsat solver
# Two boxes (lengths 2 and 3) that must not overlap on a line; minimize extent.
m = pyo.ConcreteModel()
m.x1 = pyo.Var(bounds=(0, 10)) # continuous positions
m.x2 = pyo.Var(bounds=(0, 10))
m.L = pyo.Var(bounds=(0, 10))
m.e1 = pyo.Constraint(expr=m.L >= m.x1 + 2)
m.e2 = pyo.Constraint(expr=m.L >= m.x2 + 3)
m.d1 = Disjunct(); m.d1.c = pyo.Constraint(expr=m.x1 + 2 <= m.x2) # box1 left of box2
m.d2 = Disjunct(); m.d2.c = pyo.Constraint(expr=m.x2 + 3 <= m.x1) # box2 left of box1
m.no = Disjunction(expr=[m.d1, m.d2])
m.obj = pyo.Objective(expr=m.L)
pyo.TransformationFactory("cp.discretize").apply_to(m) # explicit; unit grid
res = pyo.SolverFactory("cpsat").solve(m, time_limit=10)
print(res.solver.termination_condition, pyo.value(m.obj)) # optimal 5.0
Solver options are passed as friendly aliases (time_limit, workers, seed,
gap) or as raw CP-SAT parameter names via options={...}, e.g.
solve(m, workers=8, options={"log_search_progress": True}).
License
Apache License 2.0. See 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 pyomo_cp-0.1.0.tar.gz.
File metadata
- Download URL: pyomo_cp-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0cec1d2f1aed95be86d6fa0bf7cb9c0123456035a5e35f8150de308aa6d921a
|
|
| MD5 |
cc6c4f57c767b67a1a66e3a266db4ba5
|
|
| BLAKE2b-256 |
706df982b6f871cd1492f7995a85d30aa30e29ffef4fbd98482a4978e1860cee
|
Provenance
The following attestation bundles were made for pyomo_cp-0.1.0.tar.gz:
Publisher:
publish.yml on devin-griff/pyomo-cp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyomo_cp-0.1.0.tar.gz -
Subject digest:
e0cec1d2f1aed95be86d6fa0bf7cb9c0123456035a5e35f8150de308aa6d921a - Sigstore transparency entry: 2042057696
- Sigstore integration time:
-
Permalink:
devin-griff/pyomo-cp@279cf43fb4a3ffb4d6fded73167a25b2cfb8552f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/devin-griff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@279cf43fb4a3ffb4d6fded73167a25b2cfb8552f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyomo_cp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyomo_cp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56da08349954b2ee4ea51db9c667733c138b9594a43da3497c335f2fbc790ef7
|
|
| MD5 |
8417d0ccab92dfe2a8e1c45c027a7557
|
|
| BLAKE2b-256 |
6ae7a6c1e31794cbaca48c045809ec9731691dd283d8832a9b9543c7614c443b
|
Provenance
The following attestation bundles were made for pyomo_cp-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on devin-griff/pyomo-cp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyomo_cp-0.1.0-py3-none-any.whl -
Subject digest:
56da08349954b2ee4ea51db9c667733c138b9594a43da3497c335f2fbc790ef7 - Sigstore transparency entry: 2042057725
- Sigstore integration time:
-
Permalink:
devin-griff/pyomo-cp@279cf43fb4a3ffb4d6fded73167a25b2cfb8552f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/devin-griff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@279cf43fb4a3ffb4d6fded73167a25b2cfb8552f -
Trigger Event:
push
-
Statement type: