Skip to content

Commit

Permalink
use GUROBI_HOME environment variable when available
Browse files Browse the repository at this point in the history
Former-commit-id: d8eef3f [formerly 0bdf9fb]
Former-commit-id: 0e40596
  • Loading branch information
h-g-s committed Jul 31, 2019
1 parent d9382e5 commit cf67e12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mip/cbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def var_get_lb(self, var: "Var") -> float:
return float(lb[var.idx])

def var_get_ub(self, var: "Var") -> float:
ub = cbclib.Cbc_getColLower(self._model)
ub = cbclib.Cbc_getColUpper(self._model)
if ub == ffi.NULL:
raise Exception('Error while getting upper bound of variables')
return float(ub[var.idx])
Expand Down
2 changes: 1 addition & 1 deletion mip/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import Enum

VERSION = '1.3.4'
VERSION = '1.3.6'

# epsilon number (practical zero)
EPS = 10e-6
Expand Down
26 changes: 19 additions & 7 deletions mip/gurobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from sys import maxsize
from typing import List, Tuple
from os.path import isfile
import os.path
from glob import glob
from os import environ
from cffi import FFI
from mip.model import Model, Solver, Column, Var, LinExpr, Constr, \
VConstrList, VVarList
Expand All @@ -13,18 +16,27 @@
found = False
lib_path = None

for major_ver in reversed(range(6, 10)):
for minor_ver in reversed(range(0, 11)):
lib_path = find_library('gurobi{}{}'.format(major_ver,
minor_ver))
if 'GUROBI_HOME' in environ:
libfile = glob(os.path.join(os.environ['GUROBI_HOME'],
'lib/libgurobi*[0-9].so'))
if libfile:
lib_path = libfile[0]

if lib_path is None:
for major_ver in reversed(range(6, 10)):
for minor_ver in reversed(range(0, 11)):
lib_path = find_library('gurobi{}{}'.format(major_ver,
minor_ver))
if lib_path is not None:
break
if lib_path is not None:
break
if lib_path is not None:
break

if lib_path is None:
raise Exception("""Gurobi not found. Plase check if the
Gurobi dynamic loadable library if reachable
Gurobi dynamic loadable library is reachable or define
the environment variable GUROBI_HOME indicating the gurobi
installation path.
""")
ffi = FFI()

Expand Down

0 comments on commit cf67e12

Please sign in to comment.