Skip to content

Commit f754b53

Browse files
authored
Small bugfix for Gurobi <10 libraries (#324)
* Extend and fix library search logic
1 parent 1d519e0 commit f754b53

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

Diff for: mip/gurobi.py

+14-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from os.path import isfile
66
import os.path
77
from glob import glob
8+
import re
89
from os import environ
910
import numbers
1011
from cffi import FFI
@@ -53,29 +54,22 @@
5354

5455
if "GUROBI_HOME" in environ:
5556
if platform.lower().startswith("win"):
56-
libfile = glob(
57-
os.path.join(os.environ["GUROBI_HOME"], "bin\\gurobi[0-9][0-9][0-9].dll")
58-
)
57+
lib_path_dir = os.path.join(os.environ["GUROBI_HOME"], "bin", "*")
58+
pattern = r"gurobi([0-9]{2,3}).dll"
59+
5960
else:
60-
libfile = glob(
61-
os.path.join(os.environ["GUROBI_HOME"], "lib/libgurobi[0-9][0-9][0-9].*")
62-
)
63-
if not libfile:
64-
libfile = glob(
65-
os.path.join(
66-
os.environ["GUROBI_HOME"],
67-
"lib/libgurobi.so.[0-9].[0-9].[0-9].*",
68-
)
69-
)
61+
lib_path_dir = os.path.join(os.environ["GUROBI_HOME"], "lib", "*")
62+
pattern = r"libgurobi([0-9]{2,3})[.].*"
7063

71-
if libfile:
72-
lib_path = libfile[0]
64+
for libfile in glob(lib_path_dir):
65+
match = re.match(pattern, os.path.basename(libfile))
66+
if match:
67+
lib_path = libfile
7368

74-
# checking gurobi version
75-
s1 = lib_path.split('"')[-1].split("/")[-1]
76-
vs = [c for c in s1 if c.isdigit()]
77-
major_ver = vs[0]
78-
minor_ver = vs[1]
69+
# checking gurobi version
70+
major_ver = match.group(1)[:-1]
71+
minor_ver = match.group(1)[-1]
72+
break
7973

8074
if lib_path is None:
8175
for major_ver in reversed(range(6, 11)):

0 commit comments

Comments
 (0)