An adapter for the Python-MIP from/to OMMX.
Project description
OMMX adapter for Python-MIP
This package provides an adapter for the Python-MIP from/to OMMX
Python-MIP as a solver in OMMX toolchain
sequenceDiagram
participant U as User
participant A as Adapter
participant P as Python-MIP
U->>A: ommx.v1.Instance
A->>U: Python-MIP model
U->>P: Python-MIP model and Parameters for Python-MIP;
P->>P: Solve with CBC, Gurobi, or other solvers
P->>U: Optimized model
U->>A: Optimized model and ommx.v1.Instance
A->>U: ommx:SolutionList
Python-MIP as a user interface to create OMMX instance
sequenceDiagram
participant U as User
participant A as Adapter
participant O as Other OMMX toolchain
U->>A: Python-MIP model
A->>U: ommx.v1.Instance
U->>O: ommx.v1.Instance and Parameters for other solver
O->>O: Solve the instance with other solver using other adapter
O->>U: ommx.v1.Solution
Usage
ommx-python-mip-adapter
can be installed from PyPI as follows:
pip install ommx-python-mip-adapter
Python-MIP can be used through ommx-python-mip-adapter
by using the following:
import ommx_python_mip_adapter as adapter
from ommx.v1 import Instance, DecisionVariable
x1 = DecisionVariable.integer(1, lower=0, upper=5)
ommx_instance = Instance.from_components(
decision_variables=[x1],
objective=x1,
constraints=[],
sense=Instance.MINIMIZE,
)
# Convert from `ommx.v1.Instance` to `mip.Model`
model = adapter.instance_to_model(ommx_instance)
model.optimize()
# Create `ommx.v1.State` from Optimized `mip.Model`
ommx_solutions = adapter.model_to_solution(model, ommx_instance)
print(ommx_solutions)
You can get ommx.v1.Instance
from a Python-MIP model as the following:
import mip
import ommx_python_mip_adapter as adapter
model = mip.Model()
x1=model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
x2=model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
model.objective = - x1 - 2 * x2
model.add_constr(x1 + x2 - 6 <= 0)
ommx_instance = adapter.model_to_instance(model)
print(ommx_instance)
Reference
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
File details
Details for the file ommx_python_mip_adapter-1.3.2.tar.gz
.
File metadata
- Download URL: ommx_python_mip_adapter-1.3.2.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78101ebc56b4a6ea008bc8c66f20886c0528c9845478d146332888627556cd67 |
|
MD5 | 4565bdbc4dcc24d7cbd439ed119a384c |
|
BLAKE2b-256 | 367960f9bbc0de79cb071105fcd377a1b62342547a71824921581b358b343f08 |