Does the cvxpy replace the max function, which is convex, by MIP formulation under the hood when shows up in the constraints (for example, $\max(x,y)\le z$) or in the objective function? In gurobipy, we need to introduce a new variable and new constraint: $L=\max(x,y)$ and $L\le z$

Then gurobipy converts it to MIP.

for example:

import gurobipy as gp
L=m.addvar(vtype='C')       # new variable 
m.addConstr(L=gp.max_(x,y)) # new constraint

L=gp.max_(x,y) is nonconvex, and gurobipy converts it to MIP convex under the hood.

$\max(x,y)\le z$ can b formulated in cvxpy as follows:

import cvxpy as cp

Does cvxpy do something similar to gurobipy?

Thanks, @xd y! My problem was the following: $$g+z\ge\max(x,y)+L$$ Does that mean it can be rewritten as $g+z\ge x+L$, $g+z\ge y+L$?


2 Answers 2


No. Firstly you should use cp.maximum instead of cp.max. Secondly, it is converted to a convex programming problem (LP in this case, like $x \leq z, y \leq z$) since it follows DCP rules, rather than introducing binary variables. To see that, you can try Cons=[cp.maximum(x, y) >= z] and solving the problem, you will see it fails to solve it.

  • $\begingroup$ My problem was like the following: $g+z>=max(x,y) +L$ This can be rewritten as: $g+z>=x +L$ $g+z>=y +L$ Thanks @xd y ! $\endgroup$ Commented Dec 5, 2022 at 2:29

Natively I am not sure since solvers that come do not have MIP capability
Scroll down for list of solvers And this link to source code max seems to suggest it uses max function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.