メインコンテンツへスキップ

Invalid argument to Model.addConstr

回答済み

コメント

2件のコメント

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Yutian,

    I'll try and help you debug, rather than give you the answer.

    The full error gives you the exact place where the error occurs:

    GurobiError                               Traceback (most recent call last)
    Cell In[4], line 89
         85 for i in var:
         86     expr = sum(xi[i] * x[i] for i in var) - y_tilde[i]  # This creates a LinExpr using Gurobi's variable x[i]
    ---> 89     m0.addConstr(z[i] >= expr)
         90     m0.addConstr(z[i] >= -expr)
         92 m0.setObjective(objective, sense=GRB.MINIMIZE)

    File src/gurobipy/model.pxi:3675, in gurobipy.Model.addConstr()

    File src/gurobipy/model.pxi:3467, in gurobipy.Model.__addConstr()

    GurobiError: Invalid argument to Model.addConstr

     

    The error is saying the addConstr method does not like something about z[i] >= expr.  If you put the following lines of code just before the line which causes the error, then it will print the value of z[i] and expr to screen.

        print(f"{z[i]=}")
        print(f"{expr=}")

    Does the output look like what you would expect?

    - Riley

     

    0
  • Yutian He
    Conversationalist
    First Question

    Hi Riley,

    Thank you for the two-line code! You are right, looks like it is not what I want, I will check it later and give you more feedback. Thank you again!

    0

サインインしてコメントを残してください。