@@ -533,8 +533,6 @@ cdef class Solution:
533
533
cdef create(SCIP* scip, SCIP_SOL* scip_sol):
534
534
if scip == NULL :
535
535
raise Warning (" cannot create Solution with SCIP* == NULL" )
536
- if scip_sol == NULL :
537
- return None
538
536
sol = Solution()
539
537
sol.sol = scip_sol
540
538
sol.scip = scip
@@ -543,11 +541,13 @@ cdef class Solution:
543
541
def __getitem__ (self , Expr expr ):
544
542
# fast track for Variable
545
543
if isinstance (expr, Variable):
544
+ self ._checkStage()
546
545
var = < Variable> expr
547
546
return SCIPgetSolVal(self .scip, self .sol, var.scip_var)
548
547
return sum (self ._evaluate(term)* coeff for term, coeff in expr.terms.items() if coeff != 0 )
549
548
550
549
def _evaluate (self , term ):
550
+ self ._checkStage()
551
551
result = 1
552
552
for var in term.vartuple:
553
553
result *= SCIPgetSolVal(self .scip, self .sol, (< Variable> var).scip_var)
@@ -560,6 +560,7 @@ cdef class Solution:
560
560
cdef SCIP_VAR* scip_var
561
561
562
562
vals = {}
563
+ self ._checkStage()
563
564
for i in range (SCIPgetNVars(self .scip)):
564
565
scip_var = SCIPgetVars(self .scip)[i]
565
566
@@ -569,6 +570,11 @@ cdef class Solution:
569
570
570
571
vals[name] = SCIPgetSolVal(self .scip, self .sol, scip_var)
571
572
return str (vals)
573
+
574
+ def _checkStage (self ):
575
+ if self .sol == NULL and not SCIPgetStage(self .scip) == SCIP_STAGE_SOLVING:
576
+ raise Warning (f" method cannot only be called in stage SOLVING without a valid solution" )
577
+
572
578
573
579
cdef class BoundChange:
574
580
""" Bound change."""
@@ -4151,6 +4157,8 @@ cdef class Model:
4151
4157
"""
4152
4158
if sol == None :
4153
4159
sol = Solution.create(self ._scip, NULL )
4160
+ if sol.sol == NULL and not self .getStage() == SCIP_STAGE_SOLVING:
4161
+ raise Warning (f" method cannot only be called in stage SOLVING without a valid solution" )
4154
4162
if original:
4155
4163
objval = SCIPgetSolOrigObj(self ._scip, sol.sol)
4156
4164
else :
0 commit comments