Skip to content

Commit 89adbf8

Browse files
committed
fix (solvers): Add compatibility shim for xpress.Namespaces
xpress.Namespaces was added in version 9.6.
1 parent 12474e7 commit 89adbf8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

linopy/solvers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@
108108

109109
available_solvers.append("xpress")
110110

111+
# xpress.Namespaces was added in xpress 9.6
112+
try:
113+
from xpress import Namespaces as xpress_Namespaces
114+
except ImportError:
115+
116+
class xpress_Namespaces:
117+
ROW = 1
118+
COLUMN = 2
119+
SET = 3
120+
121+
111122
with contextlib.suppress(ModuleNotFoundError):
112123
import mosek
113124

@@ -1605,13 +1616,13 @@ def solve_problem_from_file(
16051616
def get_solver_solution() -> Solution:
16061617
objective = m.getObjVal()
16071618

1608-
var = m.getnamelist(xpress.Namespaces.COLUMN, 0, m.attributes.cols - 1)
1619+
var = m.getnamelist(xpress_Namespaces.COLUMN, 0, m.attributes.cols - 1)
16091620
sol = pd.Series(m.getSolution(), index=var, dtype=float)
16101621

16111622
try:
16121623
_dual = m.getDual()
16131624
constraints = m.getnamelist(
1614-
xpress.Namespaces.ROW, 0, m.attributes.rows - 1
1625+
xpress_Namespaces.ROW, 0, m.attributes.rows - 1
16151626
)
16161627
dual = pd.Series(_dual, index=constraints, dtype=float)
16171628
except (xpress.SolverError, xpress.ModelError, SystemError):

0 commit comments

Comments
 (0)