0

I am trying to implement an euclidean distance constraint in cplex python and I am facing a problem. The constraint is ∣∣x0 − xi ∣∣ ≤ r + M (1 − ti).


M=max(xlim,ylim)/2 
inst.variables.add(obj=[1], lb=[0.0], ub=[M], types="C", names=[Radius]) 
inst.variables.add(obj=[0], lb=[0.0], ub=[xlim], types="C", names=[X]) 
inst.variables.add(obj=[0], lb=[0.0], ub=[ylim], types="C", names=[Y]) 
for i in nodes:         
    inst.variables.add(obj=[0], lb=[0], ub=[1], types="B", names=[x_bin[i]])     
for i in nodes:         
    var1 = [X, Y, Radius]         
    coeff1 = [1, 1, -1]         
    for j in vertices[i][:len(vertices[i]) - 1]: 
        var2 = [X,Y, x_bin[i]]
        coeff2 = [-2.0*j[0], -2.0*j[1], M**2]
        rhhs = M**2 - j[0] ** 2 - j[1] ** 2
        inst.quadratic_constraints.add(
            lin_expr=cplex.SparsePair(var2, coeff2),
            quad_expr=cplex.SparseTriple(var1, var1,coeff1),
            rhs=rhhs,
            sense="L",
            name="Quadratic_Constraint"+str(i))

That is the code I am using. And I get the error "CPLEX Error 5002: 'Quadratic_Constraint101' is not convex." But the constraint is a typical SOCP (second order cone problem) constraint. Can someone please help?

  • Maybe you can let Cplex write out an LP file (not sure if it does this before the error). That would be easier to read and to check. – Erwin Kalvelagen Feb 13 '23 at 16:15

0 Answers0