5

How to formulate the following constraint using gurobipy

$$ \sqrt{x^2 + y^2} \le z$$

where $x, y, z$ are continuous optimization variables?


I saw how to formulate it using CVXPY:

cp.norm(cp.hstack([x, y])) <= z

I am now wondering how to formulate it in gurobipy. I did not find any information on how to formulate the norm convex function in the gurobipy documentation.

If take the square of both sides,

$$ x^2 + y^2 \le z^2 $$

gurobipy solves it but doesn't this constraint violate DCP rules? I thought the constraint will be following the DCP rules if convex $\leq$ constant, convex $\leq$ concave, but here it is convex $\leq$ convex.

Hussein Sharadga
  • 409
  • 1
  • 10

1 Answers1

3

Thanks to the Gurobi staff, this is how to formulate it using the norm constraint:

import gurobipy as gp
m=gp.Model()
m.addGenConstrNorm(aux, [x, y], 2, "normconstr")
m.addConstr(aux<=z)

Ref: https://support.gurobi.com/hc/en-us/community/posts/10762215603345-SOCP

Hussein Sharadga
  • 409
  • 1
  • 10