1
$\begingroup$

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
m=gp.Model()
x=m.addvar(vtype='C')       
y=m.addvar(vtype='C')       
z=m.addvar(vtype='C')       
L=m.addvar(vtype='C')       # new variable 
m.addConstr(L=gp.max_(x,y)) # new constraint
m.addaddConstr(L<=z)

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
Cons=[cp.max(x,y)<=z]

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$?

$\endgroup$

2 Answers 2

2
$\begingroup$

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.

$\endgroup$
1
  • $\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
2
$\begingroup$

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.

$\endgroup$

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.