E-TE0617 — Unsupported operand for -=

Error Type

Type Error

Phase

subtracting from a problem’s objective with -=

Python exception

TypeError (builtin)

Message

Unsupported operand type(s) for `-=`: `Problem` and `{type_name}`.

Only an expression can be subtracted from a problem's objective (constraints cannot be removed with `-=`).

Cause

The right-hand side of problem -= ... cannot be interpreted as an expression. problem -= expr subtracts expr from the objective; unlike +=, the in-place subtraction does not accept a Constraint, so problem -= constraint also raises this error.

Fix

Pass an expression to -=, for example problem -= 2 * x[0]. There is no operator for removing a registered constraint; define the problem without that constraint instead of trying to subtract it.