ommx-python-mip-adapter 3.0.0b8__tar.gz → 3.0.0rc1__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.
Files changed (22) hide show
  1. ommx_python_mip_adapter-3.0.0rc1/PKG-INFO +68 -0
  2. ommx_python_mip_adapter-3.0.0rc1/README.md +47 -0
  3. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter/adapter.py +14 -14
  4. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter/python_mip_to_ommx.py +1 -1
  5. ommx_python_mip_adapter-3.0.0rc1/ommx_python_mip_adapter.egg-info/PKG-INFO +68 -0
  6. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter.egg-info/requires.txt +1 -1
  7. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/pyproject.toml +4 -4
  8. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/tests/test_adapter.py +45 -21
  9. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/tests/test_constant_constraint.py +2 -2
  10. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/tests/test_integration.py +33 -14
  11. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/tests/test_model_to_instance.py +8 -8
  12. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/tests/test_tracing.py +2 -2
  13. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/tests/test_unknown_constraint_family.py +1 -1
  14. ommx_python_mip_adapter-3.0.0b8/PKG-INFO +0 -105
  15. ommx_python_mip_adapter-3.0.0b8/README.md +0 -84
  16. ommx_python_mip_adapter-3.0.0b8/ommx_python_mip_adapter.egg-info/PKG-INFO +0 -105
  17. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter/__init__.py +0 -0
  18. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter/exception.py +0 -0
  19. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter.egg-info/SOURCES.txt +0 -0
  20. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter.egg-info/dependency_links.txt +0 -0
  21. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/ommx_python_mip_adapter.egg-info/top_level.txt +0 -0
  22. {ommx_python_mip_adapter-3.0.0b8 → ommx_python_mip_adapter-3.0.0rc1}/setup.cfg +0 -0
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: ommx_python_mip_adapter
3
+ Version: 3.0.0rc1
4
+ Summary: An adapter for the Python-MIP from/to OMMX.
5
+ Author-email: "Jij Inc." <info@j-ij.com>
6
+ Project-URL: Documentation, https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html
7
+ Project-URL: Repository, https://github.com/Jij-Inc/ommx
8
+ Project-URL: Issues, https://github.com/Jij-Inc/ommx/issues
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: ommx<4.0.0,>=3.0.0rc1
19
+ Requires-Dist: mip<2.0.0,>=1.17.0
20
+ Requires-Dist: cffi<2.0.0,>=1.15.0
21
+
22
+ # OMMX adapter for Python-MIP
23
+
24
+ Solve a linear OMMX Instance with [Python-MIP](https://www.python-mip.com/), or import a Python-MIP model as an OMMX Instance to evaluate it or use another solver.
25
+
26
+ [Installation from a prerelease or `main`](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/getting_started/install.html#install-python-mip-adapter) · [日本語の導入手順](https://jij-inc-ommx.readthedocs-hosted.com/ja/latest/getting_started/install.html#install-python-mip-adapter)
27
+
28
+ ## Solve an OMMX problem
29
+
30
+ ```python markdown-code-runner
31
+ from ommx_python_mip_adapter import OMMXPythonMIPAdapter
32
+ from ommx import DecisionVariable, Instance, Sense
33
+
34
+ x1 = DecisionVariable.integer(1, lower=0, upper=5)
35
+ ommx_instance = Instance.from_components(
36
+ decision_variables=[x1],
37
+ objective=x1,
38
+ active_constraints={},
39
+ sense=Sense.Minimize,
40
+ )
41
+
42
+ ommx_solution = OMMXPythonMIPAdapter.solve(ommx_instance)
43
+
44
+ print(ommx_solution)
45
+ ```
46
+
47
+ ## Import a Python-MIP model
48
+
49
+ ```python markdown-code-runner
50
+ import mip
51
+ import ommx_python_mip_adapter as adapter
52
+
53
+ model = mip.Model()
54
+ x1 = model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
55
+ x2 = model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
56
+ model.objective = -x1 - 2 * x2
57
+ model.add_constr(x1 + x2 - 6 <= 0)
58
+
59
+ ommx_instance = adapter.model_to_instance(model)
60
+
61
+ print(ommx_instance)
62
+ ```
63
+
64
+ ## Reference
65
+
66
+ [Python-MIP adapter API](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.OMMXPythonMIPAdapter) · [日本語サイトのAPI Reference](https://jij-inc-ommx.readthedocs-hosted.com/ja/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.OMMXPythonMIPAdapter)
67
+
68
+ The [model conversion reference](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.model_to_instance) covers the supported input and includes an executable example.
@@ -0,0 +1,47 @@
1
+ # OMMX adapter for Python-MIP
2
+
3
+ Solve a linear OMMX Instance with [Python-MIP](https://www.python-mip.com/), or import a Python-MIP model as an OMMX Instance to evaluate it or use another solver.
4
+
5
+ [Installation from a prerelease or `main`](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/getting_started/install.html#install-python-mip-adapter) · [日本語の導入手順](https://jij-inc-ommx.readthedocs-hosted.com/ja/latest/getting_started/install.html#install-python-mip-adapter)
6
+
7
+ ## Solve an OMMX problem
8
+
9
+ ```python markdown-code-runner
10
+ from ommx_python_mip_adapter import OMMXPythonMIPAdapter
11
+ from ommx import DecisionVariable, Instance, Sense
12
+
13
+ x1 = DecisionVariable.integer(1, lower=0, upper=5)
14
+ ommx_instance = Instance.from_components(
15
+ decision_variables=[x1],
16
+ objective=x1,
17
+ active_constraints={},
18
+ sense=Sense.Minimize,
19
+ )
20
+
21
+ ommx_solution = OMMXPythonMIPAdapter.solve(ommx_instance)
22
+
23
+ print(ommx_solution)
24
+ ```
25
+
26
+ ## Import a Python-MIP model
27
+
28
+ ```python markdown-code-runner
29
+ import mip
30
+ import ommx_python_mip_adapter as adapter
31
+
32
+ model = mip.Model()
33
+ x1 = model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
34
+ x2 = model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
35
+ model.objective = -x1 - 2 * x2
36
+ model.add_constr(x1 + x2 - 6 <= 0)
37
+
38
+ ommx_instance = adapter.model_to_instance(model)
39
+
40
+ print(ommx_instance)
41
+ ```
42
+
43
+ ## Reference
44
+
45
+ [Python-MIP adapter API](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.OMMXPythonMIPAdapter) · [日本語サイトのAPI Reference](https://jij-inc-ommx.readthedocs-hosted.com/ja/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.OMMXPythonMIPAdapter)
46
+
47
+ The [model conversion reference](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.model_to_instance) covers the supported input and includes an executable example.
@@ -25,7 +25,7 @@ from ommx import (
25
25
  PreparationPolicy,
26
26
  Sense,
27
27
  Solution,
28
- SpecialConstraintKind,
28
+ ConstraintKind,
29
29
  SpecialConstraintPreparation,
30
30
  State,
31
31
  )
@@ -68,9 +68,9 @@ class OMMXPythonMIPAdapter(SolverAdapter):
68
68
  return PreparationPolicy(
69
69
  special_constraints=SpecialConstraintPreparation.lower_special_constraints(
70
70
  kinds={
71
- SpecialConstraintKind.Indicator,
72
- SpecialConstraintKind.OneHot,
73
- SpecialConstraintKind.Sos1,
71
+ ConstraintKind.Indicator,
72
+ ConstraintKind.OneHot,
73
+ ConstraintKind.Sos1,
74
74
  }
75
75
  )
76
76
  )
@@ -157,7 +157,7 @@ class OMMXPythonMIPAdapter(SolverAdapter):
157
157
  >>> instance = Instance.from_components(
158
158
  ... decision_variables=x,
159
159
  ... objective=sum(p[i] * x[i] for i in range(6)),
160
- ... constraints={0: sum(w[i] * x[i] for i in range(6)) <= 47},
160
+ ... active_constraints={0: sum(w[i] * x[i] for i in range(6)) <= 47},
161
161
  ... sense=Sense.Maximize,
162
162
  ... )
163
163
 
@@ -192,7 +192,7 @@ class OMMXPythonMIPAdapter(SolverAdapter):
192
192
  >>> instance = Instance.from_components(
193
193
  ... decision_variables=[x],
194
194
  ... objective=x,
195
- ... constraints={0: x >= 4},
195
+ ... active_constraints={0: x >= 4},
196
196
  ... sense=Sense.Maximize,
197
197
  ... )
198
198
 
@@ -212,7 +212,7 @@ class OMMXPythonMIPAdapter(SolverAdapter):
212
212
  >>> instance = Instance.from_components(
213
213
  ... decision_variables=[x],
214
214
  ... objective=x,
215
- ... constraints={},
215
+ ... active_constraints={},
216
216
  ... sense=Sense.Maximize,
217
217
  ... )
218
218
 
@@ -233,7 +233,7 @@ class OMMXPythonMIPAdapter(SolverAdapter):
233
233
  >>> instance = Instance.from_components(
234
234
  ... decision_variables=[x, y],
235
235
  ... objective=x + y,
236
- ... constraints={0: x + y <= 1},
236
+ ... active_constraints={0: x + y <= 1},
237
237
  ... sense=Sense.Maximize,
238
238
  ... )
239
239
 
@@ -313,7 +313,7 @@ class OMMXPythonMIPAdapter(SolverAdapter):
313
313
  >>> instance = Instance.from_components(
314
314
  ... decision_variables=x,
315
315
  ... objective=sum(p[i] * x[i] for i in range(6)),
316
- ... constraints={0: sum(w[i] * x[i] for i in range(6)) <= 47},
316
+ ... active_constraints={0: sum(w[i] * x[i] for i in range(6)) <= 47},
317
317
  ... sense=Sense.Maximize,
318
318
  ... )
319
319
 
@@ -367,7 +367,7 @@ class OMMXPythonMIPAdapter(SolverAdapter):
367
367
  >>> ommx_instance = Instance.from_components(
368
368
  ... decision_variables=[x1],
369
369
  ... objective=x1,
370
- ... constraints={},
370
+ ... active_constraints={},
371
371
  ... sense=Sense.Minimize,
372
372
  ... )
373
373
  >>> adapter = OMMXPythonMIPAdapter(ommx_instance)
@@ -405,12 +405,12 @@ class OMMXPythonMIPAdapter(SolverAdapter):
405
405
  return State(
406
406
  entries={
407
407
  var.id: data.var_by_name(str(var.id)).x # type: ignore
408
- for var in self.instance.used_decision_variables
408
+ for var in self.instance.active_decision_variables
409
409
  }
410
410
  )
411
411
 
412
412
  def _set_decision_variables(self):
413
- for var in self.instance.used_decision_variables:
413
+ for var in self.instance.active_decision_variables:
414
414
  if var.kind == Kind.Binary:
415
415
  self.model.add_var(
416
416
  name=str(var.id),
@@ -471,12 +471,12 @@ class OMMXPythonMIPAdapter(SolverAdapter):
471
471
 
472
472
  def _set_constraints(self):
473
473
  self._constraint_names: dict[ConstraintID, str] = {}
474
- for cid in self.instance.constraints:
474
+ for cid in self.instance.active_constraints:
475
475
  if not isinstance(cid, ConstraintID):
476
476
  raise OMMXPythonMIPAdapterError(
477
477
  f"Unsupported constraint family: {type(cid).__name__} (id: {cid})"
478
478
  )
479
- constraint = self.instance.constraints[cid]
479
+ constraint = self.instance.active_constraints[cid]
480
480
  lin_expr = self._as_lin_expr(constraint.function)
481
481
  if constraint.equality == Equality.EqualToZero:
482
482
  constr_expr = lin_expr == 0
@@ -130,7 +130,7 @@ class OMMXInstanceBuilder:
130
130
  return Instance.from_components(
131
131
  decision_variables=self.decision_variables(),
132
132
  objective=self.objective(),
133
- constraints=self.constraints(),
133
+ active_constraints=self.constraints(),
134
134
  sense=self.sense(),
135
135
  )
136
136
 
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: ommx_python_mip_adapter
3
+ Version: 3.0.0rc1
4
+ Summary: An adapter for the Python-MIP from/to OMMX.
5
+ Author-email: "Jij Inc." <info@j-ij.com>
6
+ Project-URL: Documentation, https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html
7
+ Project-URL: Repository, https://github.com/Jij-Inc/ommx
8
+ Project-URL: Issues, https://github.com/Jij-Inc/ommx/issues
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: ommx<4.0.0,>=3.0.0rc1
19
+ Requires-Dist: mip<2.0.0,>=1.17.0
20
+ Requires-Dist: cffi<2.0.0,>=1.15.0
21
+
22
+ # OMMX adapter for Python-MIP
23
+
24
+ Solve a linear OMMX Instance with [Python-MIP](https://www.python-mip.com/), or import a Python-MIP model as an OMMX Instance to evaluate it or use another solver.
25
+
26
+ [Installation from a prerelease or `main`](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/getting_started/install.html#install-python-mip-adapter) · [日本語の導入手順](https://jij-inc-ommx.readthedocs-hosted.com/ja/latest/getting_started/install.html#install-python-mip-adapter)
27
+
28
+ ## Solve an OMMX problem
29
+
30
+ ```python markdown-code-runner
31
+ from ommx_python_mip_adapter import OMMXPythonMIPAdapter
32
+ from ommx import DecisionVariable, Instance, Sense
33
+
34
+ x1 = DecisionVariable.integer(1, lower=0, upper=5)
35
+ ommx_instance = Instance.from_components(
36
+ decision_variables=[x1],
37
+ objective=x1,
38
+ active_constraints={},
39
+ sense=Sense.Minimize,
40
+ )
41
+
42
+ ommx_solution = OMMXPythonMIPAdapter.solve(ommx_instance)
43
+
44
+ print(ommx_solution)
45
+ ```
46
+
47
+ ## Import a Python-MIP model
48
+
49
+ ```python markdown-code-runner
50
+ import mip
51
+ import ommx_python_mip_adapter as adapter
52
+
53
+ model = mip.Model()
54
+ x1 = model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
55
+ x2 = model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
56
+ model.objective = -x1 - 2 * x2
57
+ model.add_constr(x1 + x2 - 6 <= 0)
58
+
59
+ ommx_instance = adapter.model_to_instance(model)
60
+
61
+ print(ommx_instance)
62
+ ```
63
+
64
+ ## Reference
65
+
66
+ [Python-MIP adapter API](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.OMMXPythonMIPAdapter) · [日本語サイトのAPI Reference](https://jij-inc-ommx.readthedocs-hosted.com/ja/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.OMMXPythonMIPAdapter)
67
+
68
+ The [model conversion reference](https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html#ommx_python_mip_adapter.model_to_instance) covers the supported input and includes an executable example.
@@ -1,3 +1,3 @@
1
- ommx<4.0.0,>=3.0.0b8
1
+ ommx<4.0.0,>=3.0.0rc1
2
2
  mip<2.0.0,>=1.17.0
3
3
  cffi<2.0.0,>=1.15.0
@@ -4,16 +4,15 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ommx_python_mip_adapter"
7
- version = "3.0.0b8"
7
+ version = "3.0.0rc1"
8
8
 
9
9
  description = "An adapter for the Python-MIP from/to OMMX."
10
10
  authors = [{ name = "Jij Inc.", email = "info@j-ij.com" }]
11
11
  readme = "README.md"
12
12
 
13
- requires-python = ">=3.10"
13
+ requires-python = ">=3.11"
14
14
  classifiers = [
15
15
  "Programming Language :: Python :: 3 :: Only",
16
- "Programming Language :: Python :: 3.10",
17
16
  "Programming Language :: Python :: 3.11",
18
17
  "Programming Language :: Python :: 3.12",
19
18
  "Programming Language :: Python :: 3.13",
@@ -23,11 +22,12 @@ classifiers = [
23
22
  ]
24
23
 
25
24
  dependencies = [
26
- "ommx >= 3.0.0b8, < 4.0.0",
25
+ "ommx >= 3.0.0rc1, < 4.0.0",
27
26
  "mip >= 1.17.0, < 2.0.0",
28
27
  "cffi >= 1.15.0, < 2.0.0",
29
28
  ]
30
29
 
31
30
  [project.urls]
31
+ Documentation = "https://jij-inc-ommx.readthedocs-hosted.com/en/latest/autoapi/ommx_python_mip_adapter/index.html"
32
32
  Repository = "https://github.com/Jij-Inc/ommx"
33
33
  Issues = "https://github.com/Jij-Inc/ommx/issues"
@@ -46,7 +46,7 @@ def test_input_class_accepts_complete_linear_mip_boundary(sense: Sense) -> None:
46
46
  instance = Instance.from_components(
47
47
  decision_variables=[x, y, z],
48
48
  objective=x + y + z,
49
- constraints={0: x + y == 1, 1: z <= 1},
49
+ active_constraints={0: x + y == 1, 1: z <= 1},
50
50
  sense=sense,
51
51
  )
52
52
 
@@ -62,7 +62,7 @@ def test_error_nonlinear_objective():
62
62
  ommx_instance = Instance.from_components(
63
63
  decision_variables=[x],
64
64
  objective=2.3 * x * x,
65
- constraints={},
65
+ active_constraints={},
66
66
  sense=Sense.Minimize,
67
67
  )
68
68
 
@@ -79,7 +79,7 @@ def test_error_non_polynomial_objective() -> None:
79
79
  instance = Instance.from_components(
80
80
  decision_variables=[x],
81
81
  objective=abs(Function(x)),
82
- constraints={},
82
+ active_constraints={},
83
83
  sense=Sense.Minimize,
84
84
  )
85
85
 
@@ -97,7 +97,7 @@ def test_error_nonlinear_constraint():
97
97
  ommx_instance = Instance.from_components(
98
98
  decision_variables=[x],
99
99
  objective=0.0,
100
- constraints={0: 2.3 * x * x == 0},
100
+ active_constraints={0: 2.3 * x * x == 0},
101
101
  sense=Sense.Minimize,
102
102
  )
103
103
 
@@ -119,13 +119,13 @@ def test_error_nonlinear_constraint():
119
119
  ),
120
120
  ],
121
121
  )
122
- def test_rejects_used_unsupported_variable_kinds(
122
+ def test_rejects_active_unsupported_variable_kinds(
123
123
  variable: DecisionVariable, kind: Kind
124
124
  ) -> None:
125
125
  instance = Instance.from_components(
126
126
  decision_variables=[variable],
127
127
  objective=variable,
128
- constraints={},
128
+ active_constraints={},
129
129
  sense=Sense.Minimize,
130
130
  )
131
131
 
@@ -138,13 +138,13 @@ def test_rejects_used_unsupported_variable_kinds(
138
138
  assert mismatch.variable_ids == {0}
139
139
 
140
140
 
141
- def test_ignores_unused_unsupported_variable_kind() -> None:
142
- used = DecisionVariable.continuous(0)
143
- unused = DecisionVariable.semi_integer(1, lower=1, upper=3)
141
+ def test_ignores_non_active_unsupported_variable_kind() -> None:
142
+ active = DecisionVariable.continuous(0)
143
+ non_active = DecisionVariable.semi_integer(1, lower=1, upper=3)
144
144
  instance = Instance.from_components(
145
- decision_variables=[used, unused],
146
- objective=used,
147
- constraints={},
145
+ decision_variables=[active, non_active],
146
+ objective=active,
147
+ active_constraints={},
148
148
  sense=Sense.Minimize,
149
149
  )
150
150
 
@@ -162,17 +162,17 @@ def test_rejects_special_constraints_without_mutating_input() -> None:
162
162
  instance = Instance.from_components(
163
163
  decision_variables=[x, y],
164
164
  objective=x + y,
165
- constraints={},
165
+ active_constraints={},
166
166
  sense=Sense.Minimize,
167
- indicator_constraints={
167
+ active_indicator_constraints={
168
168
  10: IndicatorConstraint(
169
169
  indicator_variable=x,
170
170
  function=y - 1,
171
171
  equality=Equality.LessThanOrEqualToZero,
172
172
  )
173
173
  },
174
- one_hot_constraints={20: OneHotConstraint(variables=[x])},
175
- sos1_constraints={30: Sos1Constraint(variables=[y])},
174
+ active_one_hot_constraints={20: OneHotConstraint(variables=[x])},
175
+ active_sos1_constraints={30: Sos1Constraint(variables=[y])},
176
176
  )
177
177
  before = instance.to_v2_bytes()
178
178
 
@@ -201,17 +201,17 @@ def test_recommended_preparation_reaches_the_python_mip_input_class() -> None:
201
201
  instance = Instance.from_components(
202
202
  decision_variables=[x, y],
203
203
  objective=x + y,
204
- constraints={},
204
+ active_constraints={},
205
205
  sense=Sense.Minimize,
206
- indicator_constraints={
206
+ active_indicator_constraints={
207
207
  10: IndicatorConstraint(
208
208
  indicator_variable=x,
209
209
  function=y - 1,
210
210
  equality=Equality.LessThanOrEqualToZero,
211
211
  )
212
212
  },
213
- one_hot_constraints={20: OneHotConstraint(variables=[x])},
214
- sos1_constraints={30: Sos1Constraint(variables=[y])},
213
+ active_one_hot_constraints={20: OneHotConstraint(variables=[x])},
214
+ active_sos1_constraints={30: Sos1Constraint(variables=[y])},
215
215
  )
216
216
  input_class = OMMXPythonMIPAdapter.INPUT_CLASS
217
217
  assert not input_class.contains(instance)
@@ -234,10 +234,34 @@ def test_dual_mapping_preserves_typed_sparse_constraint_ids():
234
234
  decision_variables=[x],
235
235
  objective=x,
236
236
  sense=Sense.Maximize,
237
- constraints={42: x <= 2},
237
+ active_constraints={42: x <= 2},
238
238
  )
239
239
  adapter = OMMXPythonMIPAdapter(instance)
240
240
  model = adapter.solver_input
241
241
  model.optimize()
242
242
  solution = adapter.decode(model)
243
243
  assert solution.get_dual_variable(42) == pytest.approx(1)
244
+
245
+
246
+ @pytest.mark.parametrize("skip_feasibility_check", [False, True])
247
+ def test_inactive_constraints_are_evaluated_but_not_imposed(skip_feasibility_check):
248
+ instance = Instance.minimize()
249
+ x = instance.new_continuous("x", lower=0, upper=2)
250
+ instance.objective = x
251
+ row = instance.add_constraint(x >= 1, "retained_requirement")
252
+ instance.deactivate_constraint(
253
+ row.constraint_id, "manual", skip_feasibility_check=skip_feasibility_check
254
+ )
255
+
256
+ solution = OMMXPythonMIPAdapter.solve_without_preparation(instance)
257
+
258
+ assert solution.state.entries[x.id] == pytest.approx(0)
259
+ assert solution.constraint_violation(row.constraint_id) == pytest.approx(1)
260
+ assert solution.feasible_relaxed
261
+ assert solution.feasible is skip_feasibility_check
262
+ assert (
263
+ solution.constraints[row.constraint_id].is_feasible(
264
+ atol=solution.feasibility_atol
265
+ )
266
+ is False
267
+ )
@@ -13,7 +13,7 @@ def test_constant_constraint_feasible():
13
13
  instance = Instance.from_components(
14
14
  decision_variables=[x],
15
15
  objective=x,
16
- constraints={
16
+ active_constraints={
17
17
  0: # 1 >= 0 is always true
18
18
  Linear(terms={}, constant=1) >= 0,
19
19
  1: x <= 1,
@@ -38,7 +38,7 @@ def test_constant_constraint_infeasible():
38
38
  instance = Instance.from_components(
39
39
  decision_variables=[x],
40
40
  objective=x,
41
- constraints={
41
+ active_constraints={
42
42
  0: # -1 >= 0 is always false
43
43
  Linear(terms={}, constant=-1) >= 0,
44
44
  1: x <= 1,
@@ -48,7 +48,7 @@ def test_integration_milp():
48
48
  ommx_instance = Instance.from_components(
49
49
  decision_variables=[x1, x2],
50
50
  objective=-x1 - x2,
51
- constraints={0: 3 * x1 - x2 <= 6, 1: -x1 + 3 * x2 <= 6},
51
+ active_constraints={0: 3 * x1 - x2 <= 6, 1: -x1 + 3 * x2 <= 6},
52
52
  sense=Sense.Minimize,
53
53
  )
54
54
 
@@ -61,13 +61,32 @@ def test_integration_milp():
61
61
  assert ommx_state.entries[2] == pytest.approx(3)
62
62
 
63
63
 
64
+ @pytest.mark.parametrize("relax, expected", [(False, 0.0), (True, 0.5)])
65
+ def test_integer_relaxation_preserves_constraints(relax: bool, expected: float):
66
+ x = DecisionVariable.binary(0)
67
+ instance = Instance.from_components(
68
+ decision_variables=[x],
69
+ objective=x,
70
+ active_constraints={0: x <= 0.5},
71
+ sense=Sense.Maximize,
72
+ )
73
+
74
+ adapter = OMMXPythonMIPAdapter(instance, relax=relax)
75
+ model = adapter.solver_input
76
+ model.optimize()
77
+
78
+ assert model.num_int == (0 if relax else 1)
79
+ assert len(model.constrs) == 1
80
+ assert adapter.decode_to_state(model).entries[0] == pytest.approx(expected)
81
+
82
+
64
83
  def test_solution_optimality():
65
84
  x = DecisionVariable.integer(1, lower=0, upper=5)
66
85
  y = DecisionVariable.integer(2, lower=0, upper=5)
67
86
  ommx_instance = Instance.from_components(
68
87
  decision_variables=[x, y],
69
88
  objective=x + y,
70
- constraints={},
89
+ active_constraints={},
71
90
  sense=Sense.Maximize,
72
91
  )
73
92
 
@@ -80,7 +99,7 @@ def test_solution_optimality_is_not_transported_through_fixed_penalty():
80
99
  instance = Instance.from_components(
81
100
  decision_variables=[x],
82
101
  objective=x,
83
- constraints={7: x == 1},
102
+ active_constraints={7: x == 1},
84
103
  sense=Sense.Minimize,
85
104
  )
86
105
  instance.to_qubo(uniform_penalty_weight=0.0)
@@ -96,7 +115,7 @@ def test_output_objective_omits_active_formulation_dual_values():
96
115
  instance = Instance.from_components(
97
116
  decision_variables=[x],
98
117
  objective=x,
99
- constraints={0: x <= 1},
118
+ active_constraints={0: x <= 1},
100
119
  sense=Sense.Maximize,
101
120
  )
102
121
  assert instance.convert_active_objective(Sense.Minimize)
@@ -114,13 +133,13 @@ def test_partial_evaluate():
114
133
  instance = Instance.from_components(
115
134
  decision_variables=x,
116
135
  objective=x[0] + x[1] + x[2],
117
- constraints={0: x[0] + x[1] + x[2] <= 1}, # one-hot constraint
136
+ active_constraints={0: x[0] + x[1] + x[2] <= 1}, # one-hot constraint
118
137
  sense=Sense.Minimize,
119
138
  )
120
- assert instance.used_decision_variables == x
139
+ assert instance.active_decision_variables == x
121
140
  partial = instance.partial_evaluate({0: 1})
122
141
  # x[0] is no longer present in the problem
123
- assert partial.used_decision_variables == x[1:]
142
+ assert partial.active_decision_variables == x[1:]
124
143
 
125
144
  solution = OMMXPythonMIPAdapter.solve(partial)
126
145
  assert [var.value for var in solution.decision_variables] == [1, 0, 0]
@@ -140,12 +159,12 @@ def test_relax_constraint():
140
159
  instance = Instance.from_components(
141
160
  decision_variables=x,
142
161
  objective=x[0] + x[1],
143
- constraints={0: x[0] + 2 * x[1] <= 1, 1: x[1] + x[2] <= 1},
162
+ active_constraints={0: x[0] + 2 * x[1] <= 1, 1: x[1] + x[2] <= 1},
144
163
  sense=Sense.Minimize,
145
164
  )
146
165
 
147
- assert instance.used_decision_variables == x
148
- instance.relax_constraint(1, "relax")
166
+ assert instance.active_decision_variables == x
167
+ instance.deactivate_constraint(1, "relax")
149
168
  # id for x[2] is listed as irrelevant
150
169
  assert instance.irrelevant_decision_variable_ids() == {x[2].id}
151
170
 
@@ -181,7 +200,7 @@ def test_integration_timelimit():
181
200
  instance = Instance.from_components(
182
201
  decision_variables=x,
183
202
  objective=sum(v[i] * x[i] for i in range(n)),
184
- constraints={0: constraint},
203
+ active_constraints={0: constraint},
185
204
  sense=Sense.Maximize,
186
205
  )
187
206
  adapter = OMMXPythonMIPAdapter(instance)
@@ -203,7 +222,7 @@ def test_infeasible_problem():
203
222
  instance = Instance.from_components(
204
223
  decision_variables=[x],
205
224
  objective=x,
206
- constraints={0: x >= 4},
225
+ active_constraints={0: x >= 4},
207
226
  sense=Sense.Maximize,
208
227
  )
209
228
  adapter = OMMXPythonMIPAdapter(instance)
@@ -220,7 +239,7 @@ def test_unbounded_problem():
220
239
  instance = Instance.from_components(
221
240
  decision_variables=[x],
222
241
  objective=x,
223
- constraints={},
242
+ active_constraints={},
224
243
  sense=Sense.Maximize,
225
244
  )
226
245
  adapter = OMMXPythonMIPAdapter(instance)
@@ -236,7 +255,7 @@ def test_decode_before_optimize():
236
255
  instance = Instance.from_components(
237
256
  decision_variables=[x],
238
257
  objective=x,
239
- constraints={},
258
+ active_constraints={},
240
259
  sense=Sense.Minimize,
241
260
  )
242
261
  adapter = OMMXPythonMIPAdapter(instance)
@@ -1,6 +1,6 @@
1
1
  import mip
2
2
 
3
- from ommx import Equality, Kind, Sense
3
+ from ommx import ConstraintKind, Equality, Kind, Sense
4
4
 
5
5
  from ommx_python_mip_adapter import model_to_instance
6
6
 
@@ -78,9 +78,9 @@ def test_milp():
78
78
  assert linear_terms[2] == -3
79
79
 
80
80
  # Check the constraints
81
- assert len(ommx_instance.constraints) == 3
81
+ assert len(ommx_instance.active_constraints) == 3
82
82
 
83
- constraint1 = ommx_instance.constraints.of_kind("regular")[0]
83
+ constraint1 = ommx_instance.active_constraints.of_kind(ConstraintKind.Regular)[0]
84
84
  assert constraint1.equality == Equality.EqualToZero
85
85
  assert constraint1.function.degree() == 1
86
86
  assert constraint1.function.constant_term == 6
@@ -89,7 +89,7 @@ def test_milp():
89
89
  assert constraint1_terms[0] == 4
90
90
  assert constraint1_terms[1] == -5
91
91
 
92
- constraint2 = ommx_instance.constraints.of_kind("regular")[1]
92
+ constraint2 = ommx_instance.active_constraints.of_kind(ConstraintKind.Regular)[1]
93
93
  assert constraint2.equality == Equality.LessThanOrEqualToZero
94
94
  assert constraint2.function.degree() == 1
95
95
  assert constraint2.function.constant_term == -9
@@ -98,7 +98,7 @@ def test_milp():
98
98
  assert constraint2_terms[0] == -7
99
99
  assert constraint2_terms[2] == 8
100
100
 
101
- constraint3 = ommx_instance.constraints.of_kind("regular")[2]
101
+ constraint3 = ommx_instance.active_constraints.of_kind(ConstraintKind.Regular)[2]
102
102
  assert constraint3.equality == Equality.LessThanOrEqualToZero
103
103
  assert constraint3.function.degree() == 1
104
104
  assert constraint3.function.constant_term == -12
@@ -160,9 +160,9 @@ def test_no_objective_model():
160
160
  assert ommx_instance.objective.num_terms() == 0 # Zero function has 0 terms
161
161
 
162
162
  # Check the constraints
163
- assert len(ommx_instance.constraints) == 2
163
+ assert len(ommx_instance.active_constraints) == 2
164
164
 
165
- constraint1 = ommx_instance.constraints.of_kind("regular")[0]
165
+ constraint1 = ommx_instance.active_constraints.of_kind(ConstraintKind.Regular)[0]
166
166
  assert constraint1.equality == Equality.EqualToZero
167
167
  assert constraint1.function.degree() == 1
168
168
  assert constraint1.function.constant_term == -5
@@ -171,7 +171,7 @@ def test_no_objective_model():
171
171
  assert constraint1_terms[0] == 1
172
172
  assert constraint1_terms[1] == 2
173
173
 
174
- constraint2 = ommx_instance.constraints.of_kind("regular")[1]
174
+ constraint2 = ommx_instance.active_constraints.of_kind(ConstraintKind.Regular)[1]
175
175
  assert constraint2.equality == Equality.EqualToZero
176
176
  assert constraint2.function.degree() == 1
177
177
  assert constraint2.function.constant_term == -10
@@ -9,7 +9,7 @@ def test_solve_emits_convert_solve_decode_spans():
9
9
  instance = Instance.from_components(
10
10
  decision_variables=x,
11
11
  objective=x[0] + x[1] + x[2],
12
- constraints={0: x[0] + x[1] + x[2] <= 2},
12
+ active_constraints={0: x[0] + x[1] + x[2] <= 2},
13
13
  sense=Sense.Minimize,
14
14
  )
15
15
 
@@ -28,7 +28,7 @@ def test_manual_flow_emits_convert_and_decode_spans():
28
28
  instance = Instance.from_components(
29
29
  decision_variables=x,
30
30
  objective=x[0] + x[1] + x[2],
31
- constraints={0: x[0] + x[1] + x[2] <= 2},
31
+ active_constraints={0: x[0] + x[1] + x[2] <= 2},
32
32
  sense=Sense.Minimize,
33
33
  )
34
34
 
@@ -17,7 +17,7 @@ def test_unknown_family_is_rejected_instead_of_omitted(key: ConstraintIDBase):
17
17
  # Exercise the consumer boundary independently of SDK applicability checks:
18
18
  # a newer SDK may recognize a family that this adapter cannot translate.
19
19
  adapter = object.__new__(OMMXPythonMIPAdapter)
20
- adapter.instance = cast(Instance, SimpleNamespace(constraints=[key]))
20
+ adapter.instance = cast(Instance, SimpleNamespace(active_constraints=[key]))
21
21
  with pytest.raises(
22
22
  OMMXPythonMIPAdapterError, match="Unsupported constraint family"
23
23
  ):
@@ -1,105 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ommx_python_mip_adapter
3
- Version: 3.0.0b8
4
- Summary: An adapter for the Python-MIP from/to OMMX.
5
- Author-email: "Jij Inc." <info@j-ij.com>
6
- Project-URL: Repository, https://github.com/Jij-Inc/ommx
7
- Project-URL: Issues, https://github.com/Jij-Inc/ommx/issues
8
- Classifier: Programming Language :: Python :: 3 :: Only
9
- Classifier: Programming Language :: Python :: 3.10
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: Programming Language :: Python :: 3.12
12
- Classifier: Programming Language :: Python :: 3.13
13
- Classifier: Programming Language :: Python :: 3.14
14
- Classifier: License :: OSI Approved :: Apache Software License
15
- Classifier: License :: OSI Approved :: MIT License
16
- Requires-Python: >=3.10
17
- Description-Content-Type: text/markdown
18
- Requires-Dist: ommx<4.0.0,>=3.0.0b8
19
- Requires-Dist: mip<2.0.0,>=1.17.0
20
- Requires-Dist: cffi<2.0.0,>=1.15.0
21
-
22
- OMMX adapter for Python-MIP
23
- ============================
24
- [![PyPI - Version](https://img.shields.io/pypi/v/ommx-python-mip-adapter)](https://pypi.org/project/ommx-python-mip-adapter/)
25
-
26
- This package provides an adapter for the [Python-MIP](https://www.python-mip.com/) from/to [OMMX](https://github.com/Jij-Inc/ommx)
27
-
28
- Python-MIP as a solver in OMMX toolchain
29
- -----------------------------------------
30
- ```mermaid
31
- sequenceDiagram
32
- participant U as User
33
- participant A as Adapter
34
- participant P as Python-MIP
35
- U->>A: ommx.Instance
36
- A->>U: Python-MIP model
37
- U->>P: Python-MIP model and Parameters for Python-MIP;
38
- P->>P: Solve with CBC, Gurobi, or other solvers
39
- P->>U: Optimized model
40
- U->>A: Optimized model and ommx.Instance
41
- A->>U: ommx.Solution
42
- ```
43
-
44
- Python-MIP as a user interface to create OMMX instance
45
- -------------------------------------------------------
46
- ```mermaid
47
- sequenceDiagram
48
- participant U as User
49
- participant A as Adapter
50
- participant O as Other OMMX toolchain
51
- U->>A: Python-MIP model
52
- A->>U: ommx.Instance
53
- U->>O: ommx.Instance and Parameters for other solver
54
- O->>O: Solve the instance with other solver using other adapter
55
- O->>U: ommx.Solution
56
- ```
57
-
58
- Usage
59
- ======
60
- `ommx-python-mip-adapter` can be installed from PyPI as follows:
61
-
62
- ```bash
63
- pip install ommx-python-mip-adapter
64
- ```
65
-
66
- Python-MIP can be used through `ommx-python-mip-adapter` by using the following:
67
-
68
- ```python markdown-code-runner
69
- from ommx_python_mip_adapter import OMMXPythonMIPAdapter
70
- from ommx import DecisionVariable, Instance, Sense
71
-
72
- x1 = DecisionVariable.integer(1, lower=0, upper=5)
73
- ommx_instance = Instance.from_components(
74
- decision_variables=[x1],
75
- objective=x1,
76
- constraints={},
77
- sense=Sense.Minimize,
78
- )
79
-
80
- # Create `ommx.Solution` from the `mip.Model`
81
- ommx_solution = OMMXPythonMIPAdapter.solve(ommx_instance)
82
-
83
- print(ommx_solution)
84
- ```
85
-
86
- You can get `ommx.Instance` from a Python-MIP model as the following:
87
-
88
- ```python markdown-code-runner
89
- import mip
90
- import ommx_python_mip_adapter as adapter
91
-
92
- model = mip.Model()
93
- x1 = model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
94
- x2 = model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
95
- model.objective = -x1 - 2 * x2
96
- model.add_constr(x1 + x2 - 6 <= 0)
97
-
98
- ommx_instance = adapter.model_to_instance(model)
99
-
100
- print(ommx_instance)
101
- ```
102
-
103
- Reference
104
- ==============
105
- - [OMMX-Python-MIP-Adapter API Reference](https://jij-inc.github.io/ommx-python-mip-adapter/index.html)
@@ -1,84 +0,0 @@
1
- OMMX adapter for Python-MIP
2
- ============================
3
- [![PyPI - Version](https://img.shields.io/pypi/v/ommx-python-mip-adapter)](https://pypi.org/project/ommx-python-mip-adapter/)
4
-
5
- This package provides an adapter for the [Python-MIP](https://www.python-mip.com/) from/to [OMMX](https://github.com/Jij-Inc/ommx)
6
-
7
- Python-MIP as a solver in OMMX toolchain
8
- -----------------------------------------
9
- ```mermaid
10
- sequenceDiagram
11
- participant U as User
12
- participant A as Adapter
13
- participant P as Python-MIP
14
- U->>A: ommx.Instance
15
- A->>U: Python-MIP model
16
- U->>P: Python-MIP model and Parameters for Python-MIP;
17
- P->>P: Solve with CBC, Gurobi, or other solvers
18
- P->>U: Optimized model
19
- U->>A: Optimized model and ommx.Instance
20
- A->>U: ommx.Solution
21
- ```
22
-
23
- Python-MIP as a user interface to create OMMX instance
24
- -------------------------------------------------------
25
- ```mermaid
26
- sequenceDiagram
27
- participant U as User
28
- participant A as Adapter
29
- participant O as Other OMMX toolchain
30
- U->>A: Python-MIP model
31
- A->>U: ommx.Instance
32
- U->>O: ommx.Instance and Parameters for other solver
33
- O->>O: Solve the instance with other solver using other adapter
34
- O->>U: ommx.Solution
35
- ```
36
-
37
- Usage
38
- ======
39
- `ommx-python-mip-adapter` can be installed from PyPI as follows:
40
-
41
- ```bash
42
- pip install ommx-python-mip-adapter
43
- ```
44
-
45
- Python-MIP can be used through `ommx-python-mip-adapter` by using the following:
46
-
47
- ```python markdown-code-runner
48
- from ommx_python_mip_adapter import OMMXPythonMIPAdapter
49
- from ommx import DecisionVariable, Instance, Sense
50
-
51
- x1 = DecisionVariable.integer(1, lower=0, upper=5)
52
- ommx_instance = Instance.from_components(
53
- decision_variables=[x1],
54
- objective=x1,
55
- constraints={},
56
- sense=Sense.Minimize,
57
- )
58
-
59
- # Create `ommx.Solution` from the `mip.Model`
60
- ommx_solution = OMMXPythonMIPAdapter.solve(ommx_instance)
61
-
62
- print(ommx_solution)
63
- ```
64
-
65
- You can get `ommx.Instance` from a Python-MIP model as the following:
66
-
67
- ```python markdown-code-runner
68
- import mip
69
- import ommx_python_mip_adapter as adapter
70
-
71
- model = mip.Model()
72
- x1 = model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
73
- x2 = model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
74
- model.objective = -x1 - 2 * x2
75
- model.add_constr(x1 + x2 - 6 <= 0)
76
-
77
- ommx_instance = adapter.model_to_instance(model)
78
-
79
- print(ommx_instance)
80
- ```
81
-
82
- Reference
83
- ==============
84
- - [OMMX-Python-MIP-Adapter API Reference](https://jij-inc.github.io/ommx-python-mip-adapter/index.html)
@@ -1,105 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ommx_python_mip_adapter
3
- Version: 3.0.0b8
4
- Summary: An adapter for the Python-MIP from/to OMMX.
5
- Author-email: "Jij Inc." <info@j-ij.com>
6
- Project-URL: Repository, https://github.com/Jij-Inc/ommx
7
- Project-URL: Issues, https://github.com/Jij-Inc/ommx/issues
8
- Classifier: Programming Language :: Python :: 3 :: Only
9
- Classifier: Programming Language :: Python :: 3.10
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: Programming Language :: Python :: 3.12
12
- Classifier: Programming Language :: Python :: 3.13
13
- Classifier: Programming Language :: Python :: 3.14
14
- Classifier: License :: OSI Approved :: Apache Software License
15
- Classifier: License :: OSI Approved :: MIT License
16
- Requires-Python: >=3.10
17
- Description-Content-Type: text/markdown
18
- Requires-Dist: ommx<4.0.0,>=3.0.0b8
19
- Requires-Dist: mip<2.0.0,>=1.17.0
20
- Requires-Dist: cffi<2.0.0,>=1.15.0
21
-
22
- OMMX adapter for Python-MIP
23
- ============================
24
- [![PyPI - Version](https://img.shields.io/pypi/v/ommx-python-mip-adapter)](https://pypi.org/project/ommx-python-mip-adapter/)
25
-
26
- This package provides an adapter for the [Python-MIP](https://www.python-mip.com/) from/to [OMMX](https://github.com/Jij-Inc/ommx)
27
-
28
- Python-MIP as a solver in OMMX toolchain
29
- -----------------------------------------
30
- ```mermaid
31
- sequenceDiagram
32
- participant U as User
33
- participant A as Adapter
34
- participant P as Python-MIP
35
- U->>A: ommx.Instance
36
- A->>U: Python-MIP model
37
- U->>P: Python-MIP model and Parameters for Python-MIP;
38
- P->>P: Solve with CBC, Gurobi, or other solvers
39
- P->>U: Optimized model
40
- U->>A: Optimized model and ommx.Instance
41
- A->>U: ommx.Solution
42
- ```
43
-
44
- Python-MIP as a user interface to create OMMX instance
45
- -------------------------------------------------------
46
- ```mermaid
47
- sequenceDiagram
48
- participant U as User
49
- participant A as Adapter
50
- participant O as Other OMMX toolchain
51
- U->>A: Python-MIP model
52
- A->>U: ommx.Instance
53
- U->>O: ommx.Instance and Parameters for other solver
54
- O->>O: Solve the instance with other solver using other adapter
55
- O->>U: ommx.Solution
56
- ```
57
-
58
- Usage
59
- ======
60
- `ommx-python-mip-adapter` can be installed from PyPI as follows:
61
-
62
- ```bash
63
- pip install ommx-python-mip-adapter
64
- ```
65
-
66
- Python-MIP can be used through `ommx-python-mip-adapter` by using the following:
67
-
68
- ```python markdown-code-runner
69
- from ommx_python_mip_adapter import OMMXPythonMIPAdapter
70
- from ommx import DecisionVariable, Instance, Sense
71
-
72
- x1 = DecisionVariable.integer(1, lower=0, upper=5)
73
- ommx_instance = Instance.from_components(
74
- decision_variables=[x1],
75
- objective=x1,
76
- constraints={},
77
- sense=Sense.Minimize,
78
- )
79
-
80
- # Create `ommx.Solution` from the `mip.Model`
81
- ommx_solution = OMMXPythonMIPAdapter.solve(ommx_instance)
82
-
83
- print(ommx_solution)
84
- ```
85
-
86
- You can get `ommx.Instance` from a Python-MIP model as the following:
87
-
88
- ```python markdown-code-runner
89
- import mip
90
- import ommx_python_mip_adapter as adapter
91
-
92
- model = mip.Model()
93
- x1 = model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
94
- x2 = model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
95
- model.objective = -x1 - 2 * x2
96
- model.add_constr(x1 + x2 - 6 <= 0)
97
-
98
- ommx_instance = adapter.model_to_instance(model)
99
-
100
- print(ommx_instance)
101
- ```
102
-
103
- Reference
104
- ==============
105
- - [OMMX-Python-MIP-Adapter API Reference](https://jij-inc.github.io/ommx-python-mip-adapter/index.html)