Skip to content

Commit 07c9d13

Browse files
fix: don't disable presolve and fix dual value retrieval for SCIP (#441)
* SCIP: Don't disable presolve, fix dual value retrieval * Remove erraneously added comment * Also ignore quadobjvar and qmatrixvar from dual solution * Update release notes * Amend the list of vars to ignore in SCIP's solution
1 parent 8eeacf3 commit 07c9d13

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

doc/release_notes.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
Release Notes
22
=============
33

4-
.. Upcoming Version
5-
.. ----------------
4+
Upcoming Version
5+
----------------
6+
7+
**Bug Fixes**
8+
9+
* Fix the retrieval of solutions from the SCIP solver, and do not turn off presolve.
610

711
Version 0.5.2
812
--------------

linopy/solvers.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def get_solver_solution() -> Solution:
471471

472472
sol = df[variables_b][2]
473473
dual = df[~variables_b][3]
474+
474475
return Solution(sol, dual, objective)
475476

476477
solution = self.safe_get_solution(status=status, func=get_solver_solution)
@@ -1341,9 +1342,6 @@ def solve_problem_from_file(
13411342
if warmstart_fn:
13421343
logger.warning("Warmstart not implemented for SCIP")
13431344

1344-
# In order to retrieve the dual values, we need to turn off presolve
1345-
m.setPresolve(scip.SCIP_PARAMSETTING.OFF)
1346-
13471345
m.optimize()
13481346

13491347
if basis_fn:
@@ -1362,21 +1360,24 @@ def solve_problem_from_file(
13621360

13631361
def get_solver_solution() -> Solution:
13641362
objective = m.getObjVal()
1363+
vars_to_ignore = {"quadobjvar", "qmatrixvar", "quadobj", "qmatrix"}
13651364

13661365
s = m.getSols()[0]
1367-
sol = pd.Series({v.name: s[v] for v in m.getVars()})
1368-
sol.drop(
1369-
["quadobjvar", "qmatrixvar"], errors="ignore", inplace=True, axis=0
1366+
sol = pd.Series(
1367+
{v.name: s[v] for v in m.getVars() if v.name not in vars_to_ignore}
13701368
)
13711369

1372-
cons = m.getConss()
1370+
cons = m.getConss(False)
13731371
if len(cons) != 0:
1374-
dual = pd.Series({c.name: m.getDualSolVal(c) for c in cons})
1375-
dual = dual[
1376-
dual.index.str.startswith("c") & ~dual.index.str.startswith("cf")
1377-
]
1372+
dual = pd.Series(
1373+
{
1374+
c.name: m.getDualSolVal(c)
1375+
for c in cons
1376+
if c.name not in vars_to_ignore
1377+
}
1378+
)
13781379
else:
1379-
logger.warning("Dual values of MILP couldn't be parsed")
1380+
logger.warning("Dual values not available (is this an MILP?)")
13801381
dual = pd.Series(dtype=float)
13811382

13821383
return Solution(sol, dual, objective)

0 commit comments

Comments
 (0)