Skip to content

Commit 996c51e

Browse files
committed
Merge branch 'highs' derived from PR #332
2 parents 2c4d42c + fcb37be commit 996c51e

19 files changed

+1938
-74
lines changed

.github/workflows/github-ci.yml

+12-16
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010

1111
steps:
1212

13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v3
1414

1515
- name: Set up Python
16-
uses: actions/setup-python@v5
16+
uses: actions/setup-python@v4
1717
with:
1818
python-version: 3.11
1919

@@ -50,10 +50,10 @@ jobs:
5050

5151
steps:
5252

53-
- uses: actions/checkout@v4
53+
- uses: actions/checkout@v3
5454

5555
- name: Set up Python ${{ matrix.python-version }}
56-
uses: actions/setup-python@v5
56+
uses: actions/setup-python@v4
5757
with:
5858
python-version: ${{ matrix.python-version }}
5959
architecture: x64
@@ -65,23 +65,19 @@ jobs:
6565
- name: Upgrade pip
6666
run: python -m pip install --upgrade pip
6767

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

72-
- name: Install mip for testing (CPython)
71+
- name: Install gurobi
7372
if: ${{ matrix.python-version != 'pypy3.9-v7.3.15' }}
74-
run: python -m pip install .[test,numpy,gurobi]
73+
run: python -m pip install .[gurobi]
74+
75+
- name: Install highs
76+
if: ${{ !contains(matrix.os, 'windows') && !(matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.9') }}
77+
run: python -m pip install .[highs]
7578

7679
- name: list installed packages
7780
run: python -m pip list
7881

79-
- name: Run tests PyPy
80-
if: ${{ matrix.python-version == 'pypy3.9-v7.3.15'}}
81-
run: |
82-
python -m pytest test --verbose --color=yes --doctest-modules --ignore="test/test_gurobi.py"
83-
8482
- name: Run tests
85-
if: ${{ matrix.python-version != 'pypy3.9-v7.3.15'}}
86-
run: |
87-
python -m pytest test --verbose --color=yes --doctest-modules -Werror
83+
run: python -m pytest test --verbose --color=yes --doctest-modules -Werror

examples/gen_cuts_mip.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
"""This example reads a MIP (in .lp or .mps), solves its linear programming
22
relaxation and then tests the impact of adding different types of cutting
3-
planes. In the end, the it informs which cut generator produced the best bound
4-
improvement."""
3+
planes. In the end, it informs which cut generator produced the best bound
4+
improvement.
5+
"""
56

67
from textwrap import shorten
7-
import sys
88
from mip import Model, CutType, OptimizationStatus
99
import mip
1010

11-
lp_path = ""
12-
1311
# using test data
1412
lp_path = mip.__file__.replace("mip/__init__.py", "test/data/1443_0-9.lp").replace(
1513
"mip\\__init__.py", "test\\data\\1443_0-9.lp"
1614
)
1715

1816
m = Model()
19-
if m.solver_name.upper() in ["GRB", "GUROBI"]:
20-
print("This feature is currently not supported in Gurobi.")
17+
if m.solver_name.upper() != mip.CBC:
18+
print("This feature is currently supported only in CBC.")
2119
else:
2220
m.read(lp_path)
2321

@@ -55,8 +53,8 @@
5553
best_cut = ct
5654

5755
print(
58-
"Linear programming relaxation bound now: %g, improvement of %.2f"
59-
% (m2.objective_value, perc_impr)
56+
f"Linear programming relaxation bound now: "
57+
f"{m2.objective_value:.2f}, improvement of {perc_impr:.2f}"
6058
)
6159
else:
6260
continue

mip/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from mip.ndarray import LinExprTensor
88
from mip.entities import Column, Constr, LinExpr, Var, ConflictGraph
99
from mip.model import *
10-
from mip._version import __version__
10+
11+
try:
12+
from ._version import __version__
13+
except ImportError:
14+
__version__ = "unknown"
1115

1216
name = "mip"

mip/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
CPLEX = "CPX" # we plan to support CPLEX in the future
3030
GRB = "GRB"
3131
GUROBI = "GRB"
32+
HIGHS = "HiGHS"
3233
SCIP = "SCIP" # we plan to support SCIP in the future
3334

3435
# variable types

mip/gurobi.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
MAX_NAME_SIZE = 512 # for variables and constraints
5252

5353
lib_path = None
54+
has_gurobi = False
5455

5556
if "GUROBI_HOME" in environ:
5657
if platform.lower().startswith("win"):
@@ -93,9 +94,9 @@
9394

9495

9596
if lib_path is None:
96-
found = False
97+
has_gurobi = False
9798
else:
98-
found = True
99+
has_gurobi = True
99100
grblib = ffi.dlopen(lib_path)
100101

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

0 commit comments

Comments
 (0)