pyomo-cp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - name: Install
21
+ run: pip install -e ".[dev]"
22
+ - name: Test
23
+ run: pytest -q
@@ -0,0 +1,26 @@
1
+ name: publish
2
+
3
+ # Publishes to PyPI on a version tag (e.g. `git tag v0.1.0 && git push --tags`).
4
+ # Uses PyPI Trusted Publishing (OIDC) -- no API token needed, but the project
5
+ # must be configured for trusted publishing on PyPI first (one-time setup).
6
+
7
+ on:
8
+ push:
9
+ tags: ["v*"]
10
+
11
+ jobs:
12
+ build-and-publish:
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ id-token: write # required for trusted publishing
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+ - name: Build sdist and wheel
22
+ run: |
23
+ python -m pip install --upgrade build
24
+ python -m build
25
+ - name: Publish to PyPI
26
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,20 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+
12
+ # Environments
13
+ .venv/
14
+ venv/
15
+ env/
16
+
17
+ # Editors / OS
18
+ .vscode/
19
+ .idea/
20
+ .DS_Store
pyomo_cp-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
pyomo_cp-0.1.0/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ pyomo-cp
2
+ Copyright 2026 Devin Griffith
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyomo-cp
3
+ Version: 0.1.0
4
+ Summary: Constraint-programming backends for Pyomo: a discretization transform plus CP solver interfaces (CP-SAT first).
5
+ Project-URL: Homepage, https://github.com/devin-griff/pyomo-cp
6
+ Project-URL: Repository, https://github.com/devin-griff/pyomo-cp
7
+ Author-email: Devin Griffith <dwg176@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: constraint-programming,cp-sat,gdp,optimization,or-tools,pyomo
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
16
+ Requires-Python: >=3.9
17
+ Requires-Dist: pyomo>=6.7
18
+ Provides-Extra: cpsat
19
+ Requires-Dist: ortools>=9.7; extra == 'cpsat'
20
+ Provides-Extra: dev
21
+ Requires-Dist: ortools>=9.7; extra == 'dev'
22
+ Requires-Dist: pytest; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # pyomo-cp
26
+
27
+ Constraint-programming backends for [Pyomo](https://www.pyomo.org/): a
28
+ discretization transform plus CP solver interfaces, starting with
29
+ [CP-SAT](https://developers.google.com/optimization/cp/cp_solver) (OR-Tools).
30
+
31
+ Pyomo can build and solve disjunctive/logical models via `pyomo.gdp`, but it can
32
+ only *solve* them by reformulating to MILP/MINLP (big-M, hull) and calling a MIP
33
+ solver. `pyomo-cp` adds the missing path: take the same model and solve it with a
34
+ constraint-programming solver, where disjunctions map to native reified
35
+ constraints instead of being reformulated.
36
+
37
+ > **Status: alpha.** Integer models, `pyomo.gdp` disjunctions, logical
38
+ > constraints / Boolean variables, and discretization of continuous variables
39
+ > (any `step`) work end-to-end via `SolverFactory('cpsat')`. Global constraints
40
+ > are not yet supported. See [ROADMAP.md](ROADMAP.md).
41
+
42
+ ## Scope
43
+
44
+ `pyomo-cp` is a **backend framework**, not a full CP modelling frontend. It
45
+ translates what Pyomo can already express:
46
+
47
+ - integer and (once discretized) continuous variables,
48
+ - linear constraints and a linear objective,
49
+ - logical constraints (`BooleanVar` / `LogicalConstraint`),
50
+ - `pyomo.gdp` disjunctions.
51
+
52
+ **Global constraints** (`alldifferent`, `no_overlap`, `element`, `cumulative`,
53
+ ...) are the heart of CP's modelling power, and Pyomo has no vocabulary for
54
+ them. Adding one is roadmap, not part of the initial scope.
55
+
56
+ CP solvers are finite-domain, so continuous variables must be discretized first.
57
+ That is an **explicit** step (`TransformationFactory('cp.discretize')`), never
58
+ automatic, because the integrality assumption is a modelling decision that
59
+ changes the problem.
60
+
61
+ ## Relationship to `pyomo.contrib.cp`
62
+
63
+ Pyomo ships an in-tree constraint-programming module, `pyomo.contrib.cp`. It is a
64
+ different tool for a different job, and the two are complementary:
65
+
66
+ | | `pyomo.contrib.cp` | this package |
67
+ |---|---|---|
68
+ | Role | CP **frontend** | CP **backend** |
69
+ | Built for | scheduling: `IntervalVar`, sequence vars, `Pulse` / step functions, precedence | solving models Pyomo already expresses — no new constructs |
70
+ | Input | a CP model written with the interval API | an existing `pyomo.gdp` / integer / logical model |
71
+ | Continuous variables | none (finite-domain only) | explicit `cp.discretize` onto a grid |
72
+ | Solver | IBM CP Optimizer (commercial, via `docplex`) | CP-SAT / OR-Tools (open-source) |
73
+
74
+ In one line: `pyomo.contrib.cp` is *write an interval/scheduling model and solve
75
+ it with CP Optimizer*; this package is *take a disjunctive/integer model you'd
76
+ otherwise reformulate to MILP and solve it (optionally discretized) with CP-SAT*.
77
+ They overlap only on logical constraints; the paradigm (interval scheduling vs
78
+ disjunctive/geometric) and the solver (commercial vs open) otherwise differ.
79
+
80
+ ## Install
81
+
82
+ ```bash
83
+ pip install "pyomo-cp[cpsat]" # includes OR-Tools for the CP-SAT backend
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ ```python
89
+ import pyomo.environ as pyo
90
+ from pyomo.gdp import Disjunct, Disjunction
91
+ import pyomo_cp # registers cp.discretize and the cpsat solver
92
+
93
+ # Two boxes (lengths 2 and 3) that must not overlap on a line; minimize extent.
94
+ m = pyo.ConcreteModel()
95
+ m.x1 = pyo.Var(bounds=(0, 10)) # continuous positions
96
+ m.x2 = pyo.Var(bounds=(0, 10))
97
+ m.L = pyo.Var(bounds=(0, 10))
98
+ m.e1 = pyo.Constraint(expr=m.L >= m.x1 + 2)
99
+ m.e2 = pyo.Constraint(expr=m.L >= m.x2 + 3)
100
+ m.d1 = Disjunct(); m.d1.c = pyo.Constraint(expr=m.x1 + 2 <= m.x2) # box1 left of box2
101
+ m.d2 = Disjunct(); m.d2.c = pyo.Constraint(expr=m.x2 + 3 <= m.x1) # box2 left of box1
102
+ m.no = Disjunction(expr=[m.d1, m.d2])
103
+ m.obj = pyo.Objective(expr=m.L)
104
+
105
+ pyo.TransformationFactory("cp.discretize").apply_to(m) # explicit; unit grid
106
+ res = pyo.SolverFactory("cpsat").solve(m, time_limit=10)
107
+ print(res.solver.termination_condition, pyo.value(m.obj)) # optimal 5.0
108
+ ```
109
+
110
+ Solver options are passed as friendly aliases (`time_limit`, `workers`, `seed`,
111
+ `gap`) or as raw CP-SAT parameter names via `options={...}`, e.g.
112
+ `solve(m, workers=8, options={"log_search_progress": True})`.
113
+
114
+ ## License
115
+
116
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,92 @@
1
+ # pyomo-cp
2
+
3
+ Constraint-programming backends for [Pyomo](https://www.pyomo.org/): a
4
+ discretization transform plus CP solver interfaces, starting with
5
+ [CP-SAT](https://developers.google.com/optimization/cp/cp_solver) (OR-Tools).
6
+
7
+ Pyomo can build and solve disjunctive/logical models via `pyomo.gdp`, but it can
8
+ only *solve* them by reformulating to MILP/MINLP (big-M, hull) and calling a MIP
9
+ solver. `pyomo-cp` adds the missing path: take the same model and solve it with a
10
+ constraint-programming solver, where disjunctions map to native reified
11
+ constraints instead of being reformulated.
12
+
13
+ > **Status: alpha.** Integer models, `pyomo.gdp` disjunctions, logical
14
+ > constraints / Boolean variables, and discretization of continuous variables
15
+ > (any `step`) work end-to-end via `SolverFactory('cpsat')`. Global constraints
16
+ > are not yet supported. See [ROADMAP.md](ROADMAP.md).
17
+
18
+ ## Scope
19
+
20
+ `pyomo-cp` is a **backend framework**, not a full CP modelling frontend. It
21
+ translates what Pyomo can already express:
22
+
23
+ - integer and (once discretized) continuous variables,
24
+ - linear constraints and a linear objective,
25
+ - logical constraints (`BooleanVar` / `LogicalConstraint`),
26
+ - `pyomo.gdp` disjunctions.
27
+
28
+ **Global constraints** (`alldifferent`, `no_overlap`, `element`, `cumulative`,
29
+ ...) are the heart of CP's modelling power, and Pyomo has no vocabulary for
30
+ them. Adding one is roadmap, not part of the initial scope.
31
+
32
+ CP solvers are finite-domain, so continuous variables must be discretized first.
33
+ That is an **explicit** step (`TransformationFactory('cp.discretize')`), never
34
+ automatic, because the integrality assumption is a modelling decision that
35
+ changes the problem.
36
+
37
+ ## Relationship to `pyomo.contrib.cp`
38
+
39
+ Pyomo ships an in-tree constraint-programming module, `pyomo.contrib.cp`. It is a
40
+ different tool for a different job, and the two are complementary:
41
+
42
+ | | `pyomo.contrib.cp` | this package |
43
+ |---|---|---|
44
+ | Role | CP **frontend** | CP **backend** |
45
+ | Built for | scheduling: `IntervalVar`, sequence vars, `Pulse` / step functions, precedence | solving models Pyomo already expresses — no new constructs |
46
+ | Input | a CP model written with the interval API | an existing `pyomo.gdp` / integer / logical model |
47
+ | Continuous variables | none (finite-domain only) | explicit `cp.discretize` onto a grid |
48
+ | Solver | IBM CP Optimizer (commercial, via `docplex`) | CP-SAT / OR-Tools (open-source) |
49
+
50
+ In one line: `pyomo.contrib.cp` is *write an interval/scheduling model and solve
51
+ it with CP Optimizer*; this package is *take a disjunctive/integer model you'd
52
+ otherwise reformulate to MILP and solve it (optionally discretized) with CP-SAT*.
53
+ They overlap only on logical constraints; the paradigm (interval scheduling vs
54
+ disjunctive/geometric) and the solver (commercial vs open) otherwise differ.
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ pip install "pyomo-cp[cpsat]" # includes OR-Tools for the CP-SAT backend
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ ```python
65
+ import pyomo.environ as pyo
66
+ from pyomo.gdp import Disjunct, Disjunction
67
+ import pyomo_cp # registers cp.discretize and the cpsat solver
68
+
69
+ # Two boxes (lengths 2 and 3) that must not overlap on a line; minimize extent.
70
+ m = pyo.ConcreteModel()
71
+ m.x1 = pyo.Var(bounds=(0, 10)) # continuous positions
72
+ m.x2 = pyo.Var(bounds=(0, 10))
73
+ m.L = pyo.Var(bounds=(0, 10))
74
+ m.e1 = pyo.Constraint(expr=m.L >= m.x1 + 2)
75
+ m.e2 = pyo.Constraint(expr=m.L >= m.x2 + 3)
76
+ m.d1 = Disjunct(); m.d1.c = pyo.Constraint(expr=m.x1 + 2 <= m.x2) # box1 left of box2
77
+ m.d2 = Disjunct(); m.d2.c = pyo.Constraint(expr=m.x2 + 3 <= m.x1) # box2 left of box1
78
+ m.no = Disjunction(expr=[m.d1, m.d2])
79
+ m.obj = pyo.Objective(expr=m.L)
80
+
81
+ pyo.TransformationFactory("cp.discretize").apply_to(m) # explicit; unit grid
82
+ res = pyo.SolverFactory("cpsat").solve(m, time_limit=10)
83
+ print(res.solver.termination_condition, pyo.value(m.obj)) # optimal 5.0
84
+ ```
85
+
86
+ Solver options are passed as friendly aliases (`time_limit`, `workers`, `seed`,
87
+ `gap`) or as raw CP-SAT parameter names via `options={...}`, e.g.
88
+ `solve(m, workers=8, options={"log_search_progress": True})`.
89
+
90
+ ## License
91
+
92
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,92 @@
1
+ # pyomo-cp roadmap
2
+
3
+ The v0.1 goal: a user writes a `pyomo.gdp` model, applies `cp.discretize`, calls
4
+ `SolverFactory('cpsat').solve(m)`, and gets the correct optimum, validated
5
+ against an independent hand-written CP-SAT model and against Gurobi/MILP.
6
+
7
+ ## Guiding principles
8
+
9
+ - **Backend framework, not a CP frontend.** Translate what Pyomo can already
10
+ express; global-constraint modelling is out of scope for v0.
11
+ - **Oracle-tested.** Every translation is validated by solving the same model two
12
+ independent ways and asserting identical optima.
13
+ - **Don't over-abstract.** Build CP-SAT as a direct emitter with a clean seam.
14
+ Introduce a solver-agnostic IR only when a second backend forces it.
15
+ - **Discretization is explicit and general.** A first-class, solver-agnostic
16
+ transform the user applies knowingly; backends never discretize silently.
17
+
18
+ ## Scope contract (v0.1)
19
+
20
+ Supported: integer/continuous-bounded `Var`; linear `Constraint`; linear
21
+ `Objective`; `pyomo.gdp` `Disjunction`/`Disjunct`; `LogicalConstraint`/
22
+ `BooleanVar`. Requires all variables bounded and data integer-scalable (exact) or
23
+ discretized (approximate, declared `step`). Must error clearly on: nonlinear
24
+ expressions, unbounded variables, global constraints.
25
+
26
+ ## Phase 0 — Scaffolding (done)
27
+
28
+ Repo, `src/pyomo_cp/` layout, `pyproject.toml` (Apache-2.0), stub
29
+ `cp.discretize` transform and `cpsat` solver, CI skeleton.
30
+ **Acceptance:** `pip install -e .` works; importing `pyomo_cp` registers
31
+ `SolverFactory('cpsat')` and `TransformationFactory('cp.discretize')`.
32
+
33
+ ## Phase 1 — CP-SAT backend for already-integer models
34
+
35
+ Model walker over `Var`/`Constraint`/`Objective`; linear extraction via
36
+ `generate_standard_repn` (reject nonlinear with a clear error); emit
37
+ `NewIntVar`/`NewBoolVar`, `m.Add(...)`, `Minimize`/`Maximize`; solve wrapper
38
+ (time limit, workers, seed), status mapping, solution load-back, Pyomo results
39
+ object.
40
+ **Acceptance:** a small pure-integer model solves via `cpsat` and matches Gurobi.
41
+
42
+ ## Phase 2 — Disjunctions and logic
43
+
44
+ `Disjunction` -> one indicator `BoolVar` per `Disjunct`, disjunct constraints
45
+ under `OnlyEnforceIf`, `AddExactlyOne`/`AddAtMostOne` per semantics (nested
46
+ handled recursively). `LogicalConstraint`/`BooleanVar` -> CP-SAT boolean
47
+ constraints.
48
+ **Acceptance:** a small disjunctive integer model matches its Gurobi (bigm/hull)
49
+ optimum.
50
+
51
+ ## Phase 3 — Discretization transform
52
+
53
+ `cp.discretize`: bounded continuous `Var` -> integer `x_int` with
54
+ `x = lb + step*x_int`; substitute; scale coefficients to integers (exact for
55
+ integer data, warn/round otherwise); **preserve disjunctions**; descale on
56
+ load-back; per-variable `step`.
57
+ **Acceptance (headline milestone):** a `pyomo.gdp` layout model, discretized and
58
+ solved with `cpsat`, reproduces the hand-written CP-SAT optima on the benchmark
59
+ instances and equals the Gurobi optima. This is the "one GDP model, two solvers"
60
+ demonstration.
61
+
62
+ ## Phase 4 — Hardening + release v0.1
63
+
64
+ Clear errors for unsupported constructs; solver-option passthrough; README
65
+ example; docs on scope and the discretization contract; green CI matrix; PyPI
66
+ trusted-publishing on tag; `v0.1.0`.
67
+
68
+ ## Cross-cutting
69
+
70
+ - **Testing:** oracle tests (vs hand CP-SAT and vs Gurobi) plus property tests
71
+ (random small models solved both ways with equal optima). Test solution
72
+ *values*, not just objectives.
73
+ - **Version drift:** CI-pin ortools/pyomo; the interface is what breaks on their
74
+ releases.
75
+
76
+ ## Post-v0 (future)
77
+
78
+ 1. **MiniZinc/FlatZinc emitter** — reaches Chuffed/Gecode/etc.; a very different
79
+ target than CP-SAT's API, so it's what forces and validates a real IR. Factor
80
+ the IR here, not before.
81
+ 2. **Global-constraint vocabulary** — modelling components (`AllDifferent`,
82
+ `NoOverlap`, `Element`, `Cumulative`) mapped to CP-SAT and MiniZinc globals;
83
+ includes recognizing a GDP no-overlap pattern to emit `AddNoOverlap2D`. This
84
+ is the "backend framework -> CP frontend" leap and effectively its own
85
+ project.
86
+ 3. **CP Optimizer backend** (docplex), once the IR exists.
87
+ 4. **Ergonomics:** warm starts, search hints, portfolio/worker config.
88
+
89
+ ## Open decisions
90
+
91
+ - Introduce the solver-agnostic IR at Phase 5 (MiniZinc), not before.
92
+ - License: Apache-2.0 (chosen: permissive, patent grant, matches OR-Tools).
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pyomo-cp"
7
+ version = "0.1.0"
8
+ description = "Constraint-programming backends for Pyomo: a discretization transform plus CP solver interfaces (CP-SAT first)."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Devin Griffith", email = "dwg176@gmail.com" }]
14
+ keywords = ["pyomo", "constraint-programming", "cp-sat", "or-tools", "gdp", "optimization"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Science/Research",
18
+ "License :: OSI Approved :: Apache Software License",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Scientific/Engineering :: Mathematics",
21
+ ]
22
+ dependencies = ["pyomo>=6.7"]
23
+
24
+ [project.optional-dependencies]
25
+ cpsat = ["ortools>=9.7"]
26
+ dev = ["pytest", "ortools>=9.7"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/devin-griff/pyomo-cp"
30
+ Repository = "https://github.com/devin-griff/pyomo-cp"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/pyomo_cp"]
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = ["tests"]
@@ -0,0 +1,25 @@
1
+ """pyomo-cp: constraint-programming backends for Pyomo.
2
+
3
+ Importing this package registers the pyomo-cp plugins:
4
+
5
+ * ``TransformationFactory('cp.discretize')`` — discretize bounded continuous
6
+ variables onto integer grids (an explicit, solver-agnostic step).
7
+ * ``SolverFactory('cpsat')`` — CP-SAT (OR-Tools) backend.
8
+
9
+ Scope for now is a *backend framework*: it translates what Pyomo can already
10
+ express (variables, linear constraints, logical constraints, and
11
+ ``pyomo.gdp`` disjunctions) to CP solvers. Global-constraint modelling is
12
+ roadmap, not yet supported. See ROADMAP.md.
13
+ """
14
+ from importlib.metadata import PackageNotFoundError, version
15
+
16
+ # Import for side effects: these modules register the plugins on import.
17
+ from . import discretize as _discretize # noqa: F401
18
+ from .backends import cpsat as _cpsat # noqa: F401
19
+
20
+ try:
21
+ __version__ = version("pyomo-cp")
22
+ except PackageNotFoundError: # not installed (e.g. running from a source tree)
23
+ __version__ = "0.0.0"
24
+
25
+ __all__ = ["__version__"]
@@ -0,0 +1,8 @@
1
+ """CP solver backends for pyomo-cp.
2
+
3
+ CP-SAT (OR-Tools) is the first backend. A MiniZinc/FlatZinc emitter (reaching
4
+ Chuffed, Gecode, and others) and an IBM CP Optimizer backend are roadmap items;
5
+ see ROADMAP.md. The solver-agnostic intermediate representation those backends
6
+ would share is intentionally deferred until a second backend exists to validate
7
+ its shape.
8
+ """