Second-order cone problem using CVXPY

Hi! Is this a convex problem (second-order cone problem (SOCP))? I solved it using CVXPY without any issues. If I try gurobipy I need to set the nonconvex parameter to 2. Please see the python code:

#Using CVXPY
import cvxpy as cp
pp = cp.Variable()
pc = cp.Variable()

qp = cp.Variable()
qc = cp.Variable()

pfr = cp.Variable()
pto = cp.Variable()


qfr = cp.Variable()
qto = cp.Variable()

constraints = [pp>=0,pc>=0,pc<=100,
               pfr>=0,qfr>=0,
               pto>=0,qto>=0,
               pfr**2+qfr**2<= 12,
               pto**2+qto**2<= 24,
               pp==pc+pfr+pto,
               qp==qc+qfr+qto
               
               ]
prob = cp.Problem(cp.Maximize(5*pc - 4*pp),constraints)

prob.solve()

# Print result.
print("The optimal value is", prob.value)
print("A solution x is")
print(pp.value)
print(pc.value)




# Using gurobipy
import numpy as np
import gurobipy as gp

m=gp.Model()
from gurobipy import GRB

m.params.nonConvex=2
pto=m.addVar(lb=0, vtype='C')
pfr=m.addVar(lb=0, vtype='C')
qto=m.addVar(lb=0, vtype='C')
qfr=m.addVar(lb=0, vtype='C')
aux=m.addVar(lb=0, vtype='C')
aux2=m.addVar(lb=0, vtype='C')
x=m.addVar(lb=0, vtype='C')
x2=m.addVar(lb=0, vtype='C')
pp=m.addVar(lb=0,ub=100, vtype='C')

pc=m.addVar(lb=0, vtype='C')

qp=m.addVar(lb=0, vtype='C')
qc=m.addVar(lb=0, vtype='C')



obj=5*pc-4*pp


m.setObjective(obj, GRB.MAXIMIZE)

m.addQConstr(pfr*pfr+qfr*qfr==aux)
m.addQConstr(pto*pto+qto*qto==aux2)

m.addGenConstrPow(aux,x,0.5,"gf")
m.addGenConstrPow(aux2,x2,0.5,"gf")

m.addConstr(x-12<=0)
m.addConstr(x2-24<=0)


m.addConstr(pc+pfr+pto==pp)
m.addConstr(qc+qfr+qto==qp)

m.optimize()

This forum is for the MATLAB tool, CVX. Although CV is related to and has a common heritage with CVXOY, it is a different tool. Please seek help in the appropriate venue.

1 Like