Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions mip/highs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"Python-MIP interface to the HiGHS solver."

import glob
import numbers
import logging
import os.path
Expand All @@ -22,30 +21,22 @@
libfile = os.environ[ENV_KEY]
logger.debug("Choosing HiGHS library {libfile} via {ENV_KEY}.")
else:
# try library shipped with highspy packaged
import highspy
# Try library from highsbox, which is optional dependency.
import highsbox
root = highsbox.highs_dist_dir()

pkg_path = os.path.dirname(highspy.__file__)

# need library matching operating system
# Need library matching operating system.
# Following: PyOptInterface/src/pyoptinterface/_src/highs.py
platform = sys.platform.lower()
if "linux" in platform:
patterns = ["highs_bindings.*.so", "_core.*.so"]
libfile = os.path.join(root, "lib", "libhighs.so")
elif platform.startswith("win"):
patterns = ["highs_bindings.*.pyd", "_core.*.pyd"]
libfile = os.path.join(root, "bin", "highs.dll")
elif any(platform.startswith(p) for p in ("darwin", "macos")):
patterns = ["highs_bindings.*.so", "_core.*.so"]
libfile = os.path.join(root, "lib", "libhighs.dylib")
else:
raise NotImplementedError(f"{sys.platform} not supported!")

# there should only be one match
matched_files = []
for pattern in patterns:
matched_files.extend(glob.glob(os.path.join(pkg_path, pattern)))
if len(matched_files) != 1:
raise FileNotFoundError(f"Could not find HiGHS library in {pkg_path}.")
[libfile] = matched_files
logger.debug("Choosing HiGHS library {libfile} via highspy package.")
logger.debug("Choosing HiGHS library {libfile} via highsbox package.")

highslib = ffi.dlopen(libfile)
has_highs = True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ numpy = [
"numpy==1.21.*; python_version=='3.7'"
]
gurobi = ["gurobipy>=8"]
highs = ["highspy>=1.5.3; python_version<='3.11'"]
highs = ["highsbox>=1.10.0"]
test = [
"pytest>=7.4",
"networkx==2.8.8; python_version>='3.8'",
Expand Down