Skip to main content

constrain error, "model.pxi"

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Felipe Bofarull
    • Gurobi-versary
    • First Question
    • First Comment
    from gurobipy import *
    import math

    #n = int(input('n = '))
    n = 4
    print(n)

    X = []

    for i in range(1,n+2):
    X.append(int(i))

    print(X)

    # Modelo
    of = Model()

    # Variables
    a = of.addVar(vtype=GRB.CONTINUOUS, name='a')
    x = {}
    y = {}
    for i in X:
    x[i] = of.addVar(vtype=GRB.CONTINUOUS, name='x')
    y[i] = of.addVar(vtype=GRB.CONTINUOUS, name='y')

    of.update()

    # Restricciones

    # R1
    for i in X:
    of.addConstr(x[i] >= 0)
    of.addConstr(y[i] >= 0)
    of.addConstr(a >= 0)

    # R2
    for i in X:
    of.addConstr(x[i] <= a)
    for i in X:
    of.addConstr(y[i] <= a)

    # R3
    for i in X:
    for j in X:
    if not i == j:
    of.addConstr(((x[j]-x[j])*(x[j]-x[j]) + (y[j]-y[i])*(y[j]-y[i])) >= 4)

    # Objetivo
    ob = 4 * a

    of.setObjective(ob, GRB.MINIMIZE)

    of.optimize()

    of.printAttr("X")
    0
  • Sonja Mars
    • Gurobi Staff

    Can you clarify what exactly you mean by error? The code seems to be fine. Just the model that comes out of it, is non-convex. Gurobi can solve this kind of problem if you add 

    of.params.nonConvex=2 

    right before the call of 

    of.optimize()

    Best,

    Sonja

    0

Post is closed for comments.