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
8 changes: 6 additions & 2 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Release Notes
=============

.. Upcoming Version
.. ----------------
Upcoming Version
----------------

**Bug Fixes**

* Fix the retrieval of solutions from the SCIP solver, and do not turn off presolve.

Version 0.5.2
--------------
Expand Down
25 changes: 13 additions & 12 deletions linopy/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@

sol = df[variables_b][2]
dual = df[~variables_b][3]

return Solution(sol, dual, objective)

solution = self.safe_get_solution(status=status, func=get_solver_solution)
Expand Down Expand Up @@ -1341,9 +1342,6 @@
if warmstart_fn:
logger.warning("Warmstart not implemented for SCIP")

# In order to retrieve the dual values, we need to turn off presolve
m.setPresolve(scip.SCIP_PARAMSETTING.OFF)

m.optimize()

if basis_fn:
Expand All @@ -1362,21 +1360,24 @@

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

s = m.getSols()[0]
sol = pd.Series({v.name: s[v] for v in m.getVars()})
sol.drop(
["quadobjvar", "qmatrixvar"], errors="ignore", inplace=True, axis=0
sol = pd.Series(
{v.name: s[v] for v in m.getVars() if v.name not in vars_to_ignore}
)

cons = m.getConss()
cons = m.getConss(False)
if len(cons) != 0:
dual = pd.Series({c.name: m.getDualSolVal(c) for c in cons})
dual = dual[
dual.index.str.startswith("c") & ~dual.index.str.startswith("cf")
]
dual = pd.Series(
{
c.name: m.getDualSolVal(c)
for c in cons
if c.name not in vars_to_ignore
}
)
else:
logger.warning("Dual values of MILP couldn't be parsed")
logger.warning("Dual values not available (is this an MILP?)")

Check warning on line 1380 in linopy/solvers.py

View check run for this annotation

Codecov / codecov/patch

linopy/solvers.py#L1380

Added line #L1380 was not covered by tests
dual = pd.Series(dtype=float)

return Solution(sol, dual, objective)
Expand Down
Loading