In version 9.0 and later of Gurobi, you may see the following error when trying to add two-sided constraints like `1 <= x <= 2` through the Python API:

`GurobiError: Constraint has no bool value (are you trying "lb <= expr <= ub"?)`

Adding two-sided constraints is not supported in Gurobi 9.0. Although the same syntax did not result in an error in Gurobi 8.1.1 and earlier, adding two-sided constraints was not supported and the behavior was not as expected. This is noted in the Gurobi 8.1.1 documentation here:

"Note that double inequality constraints, like `1 <= x + y <= 2` or `1 <= x[i] + y[i] <= 2 for i in range(3)` are **NOT** supported in this API, and will result in one of the inequalities to be silently disregarded, which will result in unexpected behavior."

For example, consider the following code:

m = Model()

x = m.addVar(name="x")

m.addConstr(1 <= x <= 2, name="twosided")

In Gurobi 8.1.1, this results in the following model (in LP format):

`Minimize`

Subject To

twosided: x <= 2

Bounds

End

Note that the constraint `1 <= x` is missing. Gurobi 9.0 actively prohibits this syntax by throwing an error, preventing unexpected behavior like this. Instead, each of the two constraints can be added to the model separately:

`m.addConstr(1 <= x, name="lefthandside")`

m.addConstr(x <= 2, name="righthandside")

## Comments

0 comments

Article is closed for comments.