@@ -541,13 +541,13 @@ cdef class Solution:
541541 def __getitem__ (self , Expr expr ):
542542 # fast track for Variable
543543 if isinstance (expr, Variable):
544- self ._checkStage()
544+ self ._checkStage(" SCIPgetSolVal " )
545545 var = < Variable> expr
546546 return SCIPgetSolVal(self .scip, self .sol, var.scip_var)
547547 return sum (self ._evaluate(term)* coeff for term, coeff in expr.terms.items() if coeff != 0 )
548548
549549 def _evaluate (self , term ):
550- self ._checkStage()
550+ self ._checkStage(" SCIPgetSolVal " )
551551 result = 1
552552 for var in term.vartuple:
553553 result *= SCIPgetSolVal(self .scip, self .sol, (< Variable> var).scip_var)
@@ -560,7 +560,7 @@ cdef class Solution:
560560 cdef SCIP_VAR* scip_var
561561
562562 vals = {}
563- self ._checkStage()
563+ self ._checkStage(" SCIPgetSolVal " )
564564 for i in range (SCIPgetNVars(self .scip)):
565565 scip_var = SCIPgetVars(self .scip)[i]
566566
@@ -571,9 +571,10 @@ cdef class Solution:
571571 vals[name] = SCIPgetSolVal(self .scip, self .sol, scip_var)
572572 return str (vals)
573573
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" )
574+ def _checkStage (self , method ):
575+ if method in [" SCIPgetSolVal" , " getSolObjVal" ]:
576+ if self .sol == NULL and not SCIPgetStage(self .scip) == SCIP_STAGE_SOLVING:
577+ raise Warning (f" {method} cannot only be called in stage SOLVING without a valid solution (current stage: {SCIPgetStage(self.scip)})" )
577578
578579
579580cdef class BoundChange:
@@ -4157,8 +4158,7 @@ cdef class Model:
41574158 """
41584159 if sol == None :
41594160 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" )
4161+ sol._checkStage(" getSolObjVal" )
41624162 if original:
41634163 objval = SCIPgetSolOrigObj(self ._scip, sol.sol)
41644164 else :
0 commit comments