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

How to add conditionals in constraints?

回答済み

コメント

4件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff 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?.
  • Daniel Espinoza

    Hi Siddharth,

    You could add a binary variable Xb and a continuous variable Xc and add the general constraints:

    Xb == 1 >> sum(X{s,p} >= 1)

    Xb == 0 >> sum(X{s,p} == 0)

    Xb == 1 >> Xc == sum(t{s})

    Xb == 0 >> Xc == 0

    and then add Xc to the objective function

    Daniel

    0
  • Mansi Bhatt
    • Gurobi-versary
    • First Comment

    Hi Daniel,

    I am alsi trying to add similar constraints to my optimization problem:

    x = IPmod.addVars(pairs, vtype=GRB.BINARY, name="x")
    y = IPmod.addVars(pairs, vtype=GRB.BINARY, name="y")

    IPmod.setObjective(quicksum(w[j]*y[i,j] for (i,j) in pairs), GRB.MINIMIZE)

    for (i,j) in pairs:
    IPmod.addConstrs((y[i,j]==1)>>(p[i]*x[i,j]+p[j]-d[j]>0), name="Unit Penalty"+str(i)+","+str(j))
    IPmod.addConstrs((y[i,j]==0)>>(p[i]*x[i,j]+p[j]-d[j]<=0), name="Unit Penalty"+str(i)+","+str(j))

    I get the following error msg: 


    File "linexpr.pxi", line 434, in gurobipy.LinExpr.__richcmp__

    NotImplementedError

    0
  • Silke Horn
    • Gurobi Staff Gurobi Staff

    In the line

    IPmod.addConstrs((y[i,j]==1)>>(p[i]*x[i,j]+p[j]-d[j]>0), name="Unit Penalty"+str(i)+","+str(j))

    try ">=0" instead of ">0". (Strict inequalities are not supported.)

    0

投稿コメントは受け付けていません。