Skip to main content

OMMX adapter for Gurobi

This package provides an adapter for Gurobi from OMMX. It allows you to solve optimization problems defined in OMMX format using Gurobi's powerful solver.

Features

  • Support for various variable types:
    • Binary variables
    • Integer variables
    • Continuous variables
  • Support for different optimization problems:
    • Linear Programming (LP)
    • Mixed Integer Linear Programming (MILP)
    • Quadratic Programming (QP)
    • Mixed Integer Quadratic Programming (MIQP)
  • Support for both minimization and maximization problems

Prerequisites

  • Python >= 3.9
  • Gurobi Optimizer and valid license
  • gurobipy >= 10.0.0
  • ommx >= 1.8.4

Installation

First, ensure you have Gurobi installed and properly licensed. Then install the OMMX Gurobi adapter using pip:

pip install ommx-gurobipy-adapter

Usage

Here's a simple example of how to use the adapter:

from ommx_gurobipy_adapter import OMMXGurobipyAdapter
from ommx.v1 import Instance, DecisionVariable

# Create decision variables
x1 = DecisionVariable.integer(1, lower=0, upper=5)
x2 = DecisionVariable.continuous(2, lower=0, upper=5)

# Create OMMX instance
instance = Instance.from_components(
    decision_variables=[x1, x2],
    objective=x1 + 2*x2,
    constraints=[
        x1 + x2 <= 5,  # Linear constraint
    ],
    sense=Instance.MAXIMIZE,
)

# Solve using Gurobi
solution = OMMXGurobipyAdapter.solve(instance)

# Access the results
print(f"Objective value: {solution.objective}")
print(f"x1 = {solution.state.entries[1]}")
print(f"x2 = {solution.state.entries[2]}")

Controlling Gurobi Parameters

If you need more control over the Gurobi solver parameters, you can use the adapter in two steps:

from ommx_gurobipy_adapter import OMMXGurobipyAdapter

# Create adapter
adapter = OMMXGurobipyAdapter(instance)

# Get Gurobi model
model = adapter.solver_input

# Set Gurobi parameters
model.setParam('TimeLimit', 60)  # Set time limit to 60 seconds
model.setParam('MIPGap', 0.01)   # Set relative MIP gap tolerance to 1%

# Solve
model.optimize()

# Get solution
solution = adapter.decode(model)

Error Handling

The adapter provides specific error types for different situations:

  • OMMXGurobipyAdapterError: Base error class for adapter-specific errors
  • InfeasibleDetected: Raised when the problem is infeasible
  • UnboundedDetected: Raised when the problem is unbounded

Example of error handling:

from ommx_gurobipy_adapter import OMMXGurobipyAdapterError
from ommx.adapter import InfeasibleDetected, UnboundedDetected

try:
    solution = OMMXGurobipyAdapter.solve(instance)
except InfeasibleDetected:
    print("Problem is infeasible")
except UnboundedDetected:
    print("Problem is unbounded")
except OMMXGurobipyAdapterError as e:
    print(f"Adapter error: {e}")

Testing

To run the test suite:

python -m pytest tests/

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Reference

For more information about OMMX, please visit: https://github.com/Jij-Inc/ommx

For Gurobi documentation, please visit: https://www.gurobi.com/documentation/

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Metadata

Release files for ommx-gurobipy-adapter 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ommx-gurobipy-adapter 0.0.3
File Size Uploaded Provenance Actions
ommx_gurobipy_adapter-0.0.3.tar.gz 40.4 kB With provenance Details for ommx_gurobipy_adapter-0.0.3.tar.gz

Release files / ommx_gurobipy_adapter-0.0.3.tar.gz

Download URL ommx_gurobipy_adapter-0.0.3.tar.gz
Size 40.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d725b93f8e13421710c5c5a156d4298e51e02256effe7477d50e5a57e15e7d2f
BLAKE2b-256 checksum
How to use checksums
d5c77c20e268c7542fe1ab968d776448c8cdd08be2c1d3792f76c752907cdcc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 17, 2025.

Transparency log

Security for ommx-gurobipy-adapter 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for ommx_gurobipy_adapter-0.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 17, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page