Search code examples
pythonscip

Retreive optimization variables values with expression


I am using PySCIPOpt to solve a ILP problem. The type of the variables I am using is either binary or integer.

When retreiving the variables using model.getVal(VariableName) I get this error for some variables:

TypeError: Argument 'var' has incorrect type (expected pyscipopt.scip.Variable, got pyscipopt.scip.Expr)

This is caused by the fact that for these variables, PySCIPOpt returns an expression instead of a value. The expression looks like:

{1: Expr({Term(): 0.0, Term(W(14,10)): 0.0,
 Term(W(14,9)): 0.0, Term(W(1,2)): 0.0,
 Term(W(13,10)): 0.0, Term(W(4,3)): 0.0,
 Term(W(13,9)): 0.0, Term(W(5,3)): 0.0,
 Term(W(12,10)): 0.0, Term(W(12,9)): 0.0,
 Term(W(2,2)): 0.0, Term(W(9,7)): 0.0,
 Term(W(11,10)): 0.0, Term(W(2,1)): 1.0}

Is is possible to force PySCIPOpt to return a value?

I tried changing the variable type from integer to continuous but that does not change the fact that an expression is returned instead of a value.

I expect PySCIPOpt to return a single value, not the full expression representing the dependency between the variable of interest and the other variables.

Thanks


Solution

  • The problem was that for this particular constraint I forgot to add model.addCons(). What confused me is the fact that the model was still valid and solvable by SCIP.