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:
x = model.addVar(name="x")
y = model.addVar(lb=1, name="y")
z = model.addVar(name="z")
model.addConstr(z == x / y)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. With this older versions, you can model \( z = x / y \) for a strictly positive \( y \) in Python:
x = model.addVar(name="x")
y = model.addVar(lb=1, name="y")
z = model.addVar(name="z")
model.addGenConstrNL(z, x / y)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.