E-TE0616 — Unsupported operand for +=
Error Type |
|
|---|---|
Phase |
adding to a problem with |
Python exception |
|
Message
Unsupported operand type(s) for `+=`: `Problem` and `{type_name}`.
Only a `Constraint` or an expression can be added to a problem.
Cause
The right-hand side of problem += ... is neither a Constraint nor a value that can be interpreted as an expression.
problem += expr adds expr as an objective term, and problem += constraint registers the constraint; anything else — for example a list of constraints, None, or an arbitrary Python object — raises this error.
Values that do convert to expressions (numbers, strings, tuples or dicts of expressions) are accepted here and instead fail later during type checking of the objective if their type does not fit.
Fix
Pass a single Constraint or a single expression to +=:
problem += x[0] + x[1] # objective term
problem += problem.Constraint("bound", x[0] <= 1) # constraint
To add several constraints, apply += once per constraint instead of passing a list.