Skip to content

Commit 123eb87

Browse files
committed
perf: use xpress c interface and order of operations improvement
1 parent e01cfed commit 123eb87

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

linopy/solvers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,7 @@ def solve_problem_from_file(
15691569

15701570
if solution_fn is not None:
15711571
try:
1572-
# TODO: possibly update saving of solution file
1573-
m.writesol(path_to_string(solution_fn))
1572+
m.writebinsol(path_to_string(solution_fn))
15741573
except Exception as err:
15751574
logger.info("Unable to save solution file. Raised error: %s", err)
15761575

@@ -1582,13 +1581,15 @@ def solve_problem_from_file(
15821581
def get_solver_solution() -> Solution:
15831582
objective = m.getObjVal()
15841583

1585-
var = [str(v) for v in m.getVariable()]
1586-
1587-
sol = pd.Series(m.getSolution(var), index=var, dtype=float)
1584+
var = m.getnamelist(xpress.Namespaces.COLUMN, 0, m.attributes.cols - 1)
1585+
sol = pd.Series(m.getSolution(), index=var, dtype=float)
15881586

15891587
try:
1590-
dual_ = [str(d) for d in m.getConstraint()]
1591-
dual = pd.Series(m.getDual(dual_), index=dual_, dtype=float)
1588+
_dual = m.getDual()
1589+
constraints = m.getnamelist(
1590+
xpress.Namespaces.ROW, 0, m.attributes.rows - 1
1591+
)
1592+
dual = pd.Series(_dual, index=constraints, dtype=float)
15921593
except (xpress.SolverError, xpress.ModelError, SystemError):
15931594
logger.warning("Dual values of MILP couldn't be parsed")
15941595
dual = pd.Series(dtype=float)

0 commit comments

Comments
 (0)