Introduction
Gurobi allows you to formulate non-linear optimization models. If these models adhere to certain properties, they are called convex. This is an important property to know about when solving an optimization model, because convexity can be algorithmically exploited to solve the model faster.
However, it can happen that when a convex model is formulated, Gurobi will claim that the model is non-convex. Starting with Gurobi 14.0 you can also check programmatically whether Gurobi detects your model as convex by using the model attribute isConvex.
What is happening?
This can happen for two reasons:
- In general, convexity is a difficult property to prove. Gurobi recognizes many convex problem structures to be convex, but not all. In Gurobi 14.0, the optimizer's capacity to detect convexity has been extended to nonlinear models in some cases.
- The convexity of a model can be impacted by reformulations and aggregations that happen in the presolve phase. Specifically, Gurobi's presolve may convert a convex model into a non-convex model.
So what can I do?
Gurobi takes special care to preserve convexity for certain mathematical structures that are known to be convex, most notably the standard second-order cone constraint of the form \( x^\top x \leq y^2 \), where \( x \in \mathbb{R}^n \) and \( y \geq 0 \). Therefore, the best option is to reformulate your model into such a standard form.
If this is not an option, then disabling presolve may also help, as Gurobi will not perform the reformulations which can convert a convex model into a non-convex model. However, disabling presolve often has a serious adverse effect on performance.
Further information
- What type of models can Gurobi solve?
- How does presolve work?
- NonConvex parameter documentation