ommx-python-mip-adapter 2.0.2__tar.gz → 2.0.3__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.
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/PKG-INFO +1 -1
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/adapter.py +2 -2
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter.egg-info/PKG-INFO +1 -1
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/pyproject.toml +1 -1
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/tests/test_integration.py +45 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/README.md +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/__init__.py +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/exception.py +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/python_mip_to_ommx.py +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter.egg-info/SOURCES.txt +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter.egg-info/dependency_links.txt +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter.egg-info/requires.txt +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter.egg-info/top_level.txt +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/setup.cfg +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/tests/test_adapter.py +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/tests/test_constant_constraint.py +0 -0
- {ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/tests/test_model_to_instance.py +0 -0
{ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/adapter.py
RENAMED
|
@@ -296,12 +296,12 @@ class OMMXPythonMIPAdapter(SolverAdapter):
|
|
|
296
296
|
return State(
|
|
297
297
|
entries={
|
|
298
298
|
var.id: data.var_by_name(str(var.id)).x # type: ignore
|
|
299
|
-
for var in self.instance.
|
|
299
|
+
for var in self.instance.used_decision_variables
|
|
300
300
|
}
|
|
301
301
|
)
|
|
302
302
|
|
|
303
303
|
def _set_decision_variables(self):
|
|
304
|
-
for var in self.instance.
|
|
304
|
+
for var in self.instance.used_decision_variables:
|
|
305
305
|
if var.kind == DecisionVariable.BINARY:
|
|
306
306
|
self.model.add_var(
|
|
307
307
|
name=str(var.id),
|
|
@@ -74,3 +74,48 @@ def test_solution_optimality():
|
|
|
74
74
|
|
|
75
75
|
solution = OMMXPythonMIPAdapter.solve(ommx_instance)
|
|
76
76
|
assert solution.optimality == Solution.OPTIMAL
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_partial_evaluate():
|
|
80
|
+
x = [DecisionVariable.binary(i, name="x", subscripts=[i]) for i in range(3)]
|
|
81
|
+
instance = Instance.from_components(
|
|
82
|
+
decision_variables=x,
|
|
83
|
+
objective=x[0] + x[1] + x[2],
|
|
84
|
+
constraints=[(x[0] + x[1] + x[2] <= 1).set_id(0)], # one-hot constraint
|
|
85
|
+
sense=Instance.MINIMIZE,
|
|
86
|
+
)
|
|
87
|
+
assert instance.used_decision_variables == x
|
|
88
|
+
partial = instance.partial_evaluate({0: 1})
|
|
89
|
+
# x[0] is no longer present in the problem
|
|
90
|
+
assert partial.used_decision_variables == x[1:]
|
|
91
|
+
|
|
92
|
+
solution = OMMXPythonMIPAdapter.solve(partial)
|
|
93
|
+
assert [var.value for var in solution.decision_variables] == [1, 0, 0]
|
|
94
|
+
assert solution.optimality == Solution.OPTIMAL
|
|
95
|
+
|
|
96
|
+
partial = instance.partial_evaluate({1: 1})
|
|
97
|
+
solution = OMMXPythonMIPAdapter.solve(partial)
|
|
98
|
+
assert [var.value for var in solution.decision_variables] == [0, 1, 0]
|
|
99
|
+
|
|
100
|
+
partial = instance.partial_evaluate({2: 1})
|
|
101
|
+
solution = OMMXPythonMIPAdapter.solve(partial)
|
|
102
|
+
assert [var.value for var in solution.decision_variables] == [0, 0, 1]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_relax_constraint():
|
|
106
|
+
x = [DecisionVariable.binary(i, name="x", subscripts=[i]) for i in range(3)]
|
|
107
|
+
instance = Instance.from_components(
|
|
108
|
+
decision_variables=x,
|
|
109
|
+
objective=x[0] + x[1],
|
|
110
|
+
constraints=[(x[0] + 2 * x[1] <= 1).set_id(0), (x[1] + x[2] <= 1).set_id(1)],
|
|
111
|
+
sense=Instance.MINIMIZE,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
assert instance.used_decision_variables == x
|
|
115
|
+
instance.relax_constraint(1, "relax")
|
|
116
|
+
# id for x[2] is listed as irrelevant
|
|
117
|
+
assert instance.decision_variable_analysis().irrelevant() == {x[2].id}
|
|
118
|
+
|
|
119
|
+
solution = OMMXPythonMIPAdapter.solve(instance)
|
|
120
|
+
# x[2] is still present as part of the evaluate/decoding process but has a value of 0
|
|
121
|
+
assert [var.value for var in solution.decision_variables] == [0, 0, 0]
|
|
File without changes
|
{ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/__init__.py
RENAMED
|
File without changes
|
{ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/ommx_python_mip_adapter/exception.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/tests/test_constant_constraint.py
RENAMED
|
File without changes
|
{ommx_python_mip_adapter-2.0.2 → ommx_python_mip_adapter-2.0.3}/tests/test_model_to_instance.py
RENAMED
|
File without changes
|