Gurobi 14.0 onward
Gurobi 14 introduces Nonlinear Constraints as a first-class modeling entity throughout the product. Unlike for the existing General Nonlinear constraints (which are deprecated in Gurobi 14), you can set constraint senses and right-hand side values through a set of newly added Nonlinear Constraint Attributes. For example, to model \( u = x \cdot y \cdot z \) in Python:
u = model.addVar(lb=-50, ub=50, name="u")
x = model.addVar(lb=-1, ub=1, name="x")
y = model.addVar(lb=-5, ub=5, name="y")
z = model.addVar(lb=1, ub=10, name="z")
model.addConstr(u == x * y * z)
Gurobi versions 12.0 and 13.0
In Gurobi 12.0 and 13.0, the syntax of first-class modeling entities was not introduced. With these older versions, the multilinear expression \( u = x \cdot y \cdot z \) in Python should be coded as:
u = model.addVar(lb=-50, ub=50, name="u")
x = model.addVar(lb=-1, ub=1, name="x")
y = model.addVar(lb=-5, ub=5, name="y")
z = model.addVar(lb=1, ub=10, name="z")
model.addGenConstrNL(u, x * y * z)
Note: Regardless of the Gurobi version, it is strongly recommended that finite lower and upper bounds are provided for all variables that occur in nonlinear terms in a given problem.