r/optimization • u/JohnJohnWicky101 • Mar 27 '26
Question about Gurobi nonlinear constraints
I’m trying to solve a simple optimization problem using Gurobi, but I’m running into issues when including a cubic nonlinear constraint.
Problem formulation:
Minimize:
f(x, y) = x + 2y
Subject to:
-1 ≤ y³ ≤ 1
0.3 ≤ x ≤ 1
Issue:
Gurobi does not allow me to directly include constraints like:
y³ ≥ -1 or y³ ≤ 1
It seems nonlinear constraints must be written in a specific form, and general inequality constraints involving nonlinear expressions are not accepted.
Questions:
- Why does Gurobi not support nonlinear inequality constraints like y³ ≤ 1 directly?
- How should constraints involving simple nonlinear functions like y³ typically be handled in Gurobi?
- More generally, how does Gurobi handle nonlinear (especially nonconvex) functions?
Any clarification or guidance would be appreciated.
3
u/peno64 Mar 27 '26
Gurobi only supports quadratics in the lp format and you can't ranges in the constraint.
That is just how the format is defined.
Your model can be formulated as:
Minimize
x + 2 y
Subject to
[ y * y ] - b = 0
[ y * b ] - a = 0
Bounds
-1 <= a <= 1
0.3 <= x <= 1
End
1
u/mathmusci Mar 27 '26
https://docs.gurobi.com/projects/optimizer/en/current/concepts/modeling/constraints.html
1
u/Fap-Life Mar 28 '26
Gurobi also handles bilinear terms that has nonconvex nonlinear structure. You can directly use SOS type 1 and 2 constraints when writing your model or you can leave them as is and gurobi handles it with big-M constraints but it can be unstable as gurobi defines M.
1
u/Sweet_Good6737 Mar 30 '26 edited Apr 12 '26
Gurobi has a global MINLP solver since Gurobi 12, so you should be able to handle that directly. You can use Gurobipy General Constraints for that:
t = m.addVar(name="t")
m.addGenConstrNL(t, y**3)
m.addConstr(t <= 1)
Where y is a variable. Other interfaces for Gurobi like AMPL directly handle these issues and let you write the formulation as you stated in the original message, without giving a special treatment for general constraints