Skip to main content

attribute error '__cindex__' using absolute value and square root

Answered

Comments

2 comments

  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    Hi María,

    How did you add your auxiliary variables?
    Doing like this

    import gurobipy as gp
    m = gp.Model("abs")

    x = m.addVars(5, vtype = gp.GRB.CONTINUOUS, name = "x")
    Iabs = m.addVar(vtype = gp.GRB.CONTINUOUS, lb = 0, name = "Iabs")
    I = gp.quicksum(x[i] for i in range(4))
    m.addGenConstrAbs(Iabs, I, "abs")

    would result in the error you mentioned.

    You need to add the auxiliary variable and the constraint also to the model:

    import gurobipy as gp
    m = gp.Model("abs")

    x = m.addVars(5, vtype = gp.GRB.CONTINUOUS, name = "x")
    Iabs = m.addVar(vtype = gp.GRB.CONTINUOUS, lb = 0, name = "y")
    I = m.addVar(vtype = gp.GRB.CONTINUOUS, name = "I")
    m.addConstr(I == gp.quicksum(x[i] for i in range(4)))
    m.addGenConstrAbs(Iabs, I, "abs")

    I hope this helps,
    Marika

    0
  • María Ciudad Alañón
    Gurobi-versary
    First Comment
    First Question

    Thank you very much! It has been very helpful!

    0

Please sign in to leave a comment.