diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index ad9af85b8..2efaae73f 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -1003,8 +1003,8 @@ cdef class Solution: """Base class holding a pointer to corresponding SCIP_SOL.""" # We are raising an error here to avoid creating a solution without an associated model. See Issue #625 - def __init__(self, raise_error = False): - if not raise_error: + def __init__(self, raise_error = True): + if raise_error: raise ValueError("To create a solution you should use the createSol method of the Model class.") @staticmethod @@ -1028,7 +1028,7 @@ cdef class Solution: """ if scip == NULL: raise Warning("cannot create Solution with SCIP* == NULL") - sol = Solution(True) + sol = Solution(raise_error=False) sol.sol = scip_sol sol.scip = scip return sol @@ -10274,6 +10274,9 @@ cdef class Model: if not stage_check or self._bestSol.sol == NULL and SCIPgetStage(self._scip) != SCIP_STAGE_SOLVING: raise Warning("Method cannot be called in stage ", self.getStage()) + # update best sol + self.getBestSol() + if isinstance(expr, MatrixExpr): result = np.empty(expr.shape, dtype=float) for idx in np.ndindex(result.shape):