@@ -541,13 +541,13 @@ cdef class Solution:
541
541
def __getitem__ (self , Expr expr ):
542
542
# fast track for Variable
543
543
if isinstance (expr, Variable):
544
- self ._checkStage()
544
+ self ._checkStage(" SCIPgetSolVal " )
545
545
var = < Variable> expr
546
546
return SCIPgetSolVal(self .scip, self .sol, var.scip_var)
547
547
return sum (self ._evaluate(term)* coeff for term, coeff in expr.terms.items() if coeff != 0 )
548
548
549
549
def _evaluate (self , term ):
550
- self ._checkStage()
550
+ self ._checkStage(" SCIPgetSolVal " )
551
551
result = 1
552
552
for var in term.vartuple:
553
553
result *= SCIPgetSolVal(self .scip, self .sol, (< Variable> var).scip_var)
@@ -560,7 +560,7 @@ cdef class Solution:
560
560
cdef SCIP_VAR* scip_var
561
561
562
562
vals = {}
563
- self ._checkStage()
563
+ self ._checkStage(" SCIPgetSolVal " )
564
564
for i in range (SCIPgetNVars(self .scip)):
565
565
scip_var = SCIPgetVars(self .scip)[i]
566
566
@@ -571,9 +571,10 @@ cdef class Solution:
571
571
vals[name] = SCIPgetSolVal(self .scip, self .sol, scip_var)
572
572
return str (vals)
573
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" )
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)})" )
577
578
578
579
579
580
cdef class BoundChange:
@@ -4157,8 +4158,7 @@ cdef class Model:
4157
4158
"""
4158
4159
if sol == None :
4159
4160
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" )
4162
4162
if original:
4163
4163
objval = SCIPgetSolOrigObj(self ._scip, sol.sol)
4164
4164
else :
0 commit comments