Skip to content

Commit

Permalink
Merge branch 'highs' derived from PR #332
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliotoffolo committed Feb 17, 2024
2 parents 2c4d42c + fcb37be commit 996c51e
Show file tree
Hide file tree
Showing 19 changed files with 1,938 additions and 74 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:

steps:

- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: 3.11

Expand Down Expand Up @@ -50,10 +50,10 @@ jobs:

steps:

- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand All @@ -65,23 +65,19 @@ jobs:
- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install mip for testing (PyPy)
if: ${{ matrix.python-version == 'pypy3.9-v7.3.15' }}
- name: Install test and numpy
run: python -m pip install .[test,numpy]

- name: Install mip for testing (CPython)
- name: Install gurobi
if: ${{ matrix.python-version != 'pypy3.9-v7.3.15' }}
run: python -m pip install .[test,numpy,gurobi]
run: python -m pip install .[gurobi]

- name: Install highs
if: ${{ !contains(matrix.os, 'windows') && !(matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.9') }}
run: python -m pip install .[highs]

- name: list installed packages
run: python -m pip list

- name: Run tests PyPy
if: ${{ matrix.python-version == 'pypy3.9-v7.3.15'}}
run: |
python -m pytest test --verbose --color=yes --doctest-modules --ignore="test/test_gurobi.py"
- name: Run tests
if: ${{ matrix.python-version != 'pypy3.9-v7.3.15'}}
run: |
python -m pytest test --verbose --color=yes --doctest-modules -Werror
run: python -m pytest test --verbose --color=yes --doctest-modules -Werror
16 changes: 7 additions & 9 deletions examples/gen_cuts_mip.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
"""This example reads a MIP (in .lp or .mps), solves its linear programming
relaxation and then tests the impact of adding different types of cutting
planes. In the end, the it informs which cut generator produced the best bound
improvement."""
planes. In the end, it informs which cut generator produced the best bound
improvement.
"""

from textwrap import shorten
import sys
from mip import Model, CutType, OptimizationStatus
import mip

lp_path = ""

# using test data
lp_path = mip.__file__.replace("mip/__init__.py", "test/data/1443_0-9.lp").replace(
"mip\\__init__.py", "test\\data\\1443_0-9.lp"
)

m = Model()
if m.solver_name.upper() in ["GRB", "GUROBI"]:
print("This feature is currently not supported in Gurobi.")
if m.solver_name.upper() != mip.CBC:
print("This feature is currently supported only in CBC.")
else:
m.read(lp_path)

Expand Down Expand Up @@ -55,8 +53,8 @@
best_cut = ct

print(
"Linear programming relaxation bound now: %g, improvement of %.2f"
% (m2.objective_value, perc_impr)
f"Linear programming relaxation bound now: "
f"{m2.objective_value:.2f}, improvement of {perc_impr:.2f}"
)
else:
continue
Expand Down
6 changes: 5 additions & 1 deletion mip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from mip.ndarray import LinExprTensor
from mip.entities import Column, Constr, LinExpr, Var, ConflictGraph
from mip.model import *
from mip._version import __version__

try:
from ._version import __version__
except ImportError:
__version__ = "unknown"

name = "mip"
1 change: 1 addition & 0 deletions mip/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
CPLEX = "CPX" # we plan to support CPLEX in the future
GRB = "GRB"
GUROBI = "GRB"
HIGHS = "HiGHS"
SCIP = "SCIP" # we plan to support SCIP in the future

# variable types
Expand Down
7 changes: 4 additions & 3 deletions mip/gurobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
MAX_NAME_SIZE = 512 # for variables and constraints

lib_path = None
has_gurobi = False

if "GUROBI_HOME" in environ:
if platform.lower().startswith("win"):
Expand Down Expand Up @@ -93,9 +94,9 @@


if lib_path is None:
found = False
has_gurobi = False
else:
found = True
has_gurobi = True
grblib = ffi.dlopen(lib_path)

ffi.cdef(
Expand Down Expand Up @@ -339,7 +340,7 @@ class SolverGurobi(Solver):
def __init__(self, model: Model, name: str, sense: str, modelp: CData = ffi.NULL):
"""modelp should be informed if a model should not be created,
but only allow access to an existing one"""
if not found:
if not has_gurobi:
raise FileNotFoundError(
"""Gurobi not found. Plase check if the
Gurobi dynamic loadable library is reachable or define
Expand Down
Loading

0 comments on commit 996c51e

Please sign in to comment.