Pyomo interface to CP-SAT
Project description
pyomo-cpsat
A Pyomo direct interface to the CP-SAT solver.
pyomo-cpsat is limited to solving pure integer linear programs with CP-SAT, or optimization models with
- a linear objective function with real coefficients,
- linear constraints with integral coefficients, and
- bounded integer variables.
pyomo-cpsat does not implement other CP-SAT constraint types, such as cumulative constraints, reservoir constraints, etc.
Through a keyword argument, pyomo-cpsat can find infeasible subsystems of constraints for infeasible models, using the approach illustrated here.
pyomo-cpsat is currently experimental - it is based on the future Pyomo solver interface documented here, still under active development.
Examples
Solving a simple model
import pyomo.environ as pyo
from pyomo.contrib.solver.common.factory import SolverFactory
import pyomo_cpsat
model = pyo.ConcreteModel()
model.I = pyo.Set(initialize=[1, 2, 3])
model.w = pyo.Param(model.I, initialize={1: 10, 2: 20, 3: 30})
model.x = pyo.Var(model.I, domain=pyo.Integers, bounds=(0, 100))
def con_rule(model):
return pyo.quicksum(model.w[i] * model.x[i] for i in model.I) <= 20
model.con = pyo.Constraint(rule=con_rule)
def obj_rule(model):
return pyo.quicksum(model.x[i] for i in model.I)
model.obj = pyo.Objective(rule=obj_rule, sense=pyo.maximize)
solver = SolverFactory('cpsat')
results = solver.solve(
model,
tee=False, # sets log_search_progress in CP-SAT
threads=8, # sets num_workers in CP-SAT
time_limit=300, # sets max_time_in_seconds in CP-SAT
rel_gap=0.1, # sets relative_gap_limit in CP-SAT
abs_gap=1e-6, # sets absolute_gap_limit in CP-SAT
solver_options={ # passes CP-SAT parameters
'subsolvers': ['pseudo_costs', 'probing']
},
)
print(f'Termination condition: {results.termination_condition}')
print(f'Solution status: {results.solution_status}')
print('Solution:')
for i in model.I:
print(f' x[{i}] = {pyo.value(model.x[i])}')
Resulting output:
Termination condition: TerminationCondition.convergenceCriteriaSatisfied
Solution status: SolutionStatus.optimal
Solution:
x[1] = 2
x[2] = 0
x[3] = 0
Finding an infeasible subsystem of constraints
import pyomo.environ as pyo
from pyomo.contrib.solver.common.factory import SolverFactory
import pyomo_cpsat
model = pyo.ConcreteModel()
model.I = pyo.Set(initialize=[1, 2, 3])
model.K = pyo.Set(initialize=['a', 'b'])
model.a = pyo.Param(
model.K,
model.I,
initialize={
('a', 1): 1,
('a', 2): 2,
('a', 3): 3,
('b', 1): -1,
('b', 2): -1,
('b', 3): -1,
},
)
model.b = pyo.Param(
model.K,
initialize={'a': 5, 'b': -10},
)
model.x = pyo.Var(model.I, domain=pyo.Integers, bounds=(0, 1))
def con_rule(model, k):
return pyo.quicksum(model.a[k, i] * model.x[i] for i in model.I) <= model.b[k]
model.con = pyo.Constraint(model.K, rule=con_rule)
def obj_rule(model):
return pyo.quicksum(model.x[i] for i in model.I)
model.obj = pyo.Objective(rule=obj_rule, sense=pyo.maximize)
solver = SolverFactory('cpsat')
results = solver.solve(model, find_infeasible_subsystem=True)
Resulting output:
Infeasible subsystem of constraints
-----------------------------------
con[b]
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
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_cpsat-2026.1.29.tar.gz.
File metadata
- Download URL: pyomo_cpsat-2026.1.29.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59b981d9f9e5229bd4b8ea1d8ca8ade35fc395f6635b0117810d9f898cf1bf74
|
|
| MD5 |
fb887f7336d0cfb7b17937a3f135af46
|
|
| BLAKE2b-256 |
981fd0f0fb5f3752737517ea4af8cc7a1032a80d4e4f9616c565e8baf678e0e3
|
File details
Details for the file pyomo_cpsat-2026.1.29-py2.py3-none-any.whl.
File metadata
- Download URL: pyomo_cpsat-2026.1.29-py2.py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dee64e48c23508213a98dfc412cf3bbb1204e5cb98d1f8cbdfc38d45b856474
|
|
| MD5 |
b2c4f8bb1af9462985786426979035d0
|
|
| BLAKE2b-256 |
ed371b500321e7d3764cc997564546d0a630c39f05bda93839198d7da8be08d7
|