Skip to main content

How to deal with the restriction of not being able to use strictly greater/smaller constraints?

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Marika Karbstein
    • Gurobi Staff

    I am not sure if I understand your setting. But isn't it enough to change the sign of eps, i.e.,

     m.addConstr((AQ[i]-Q[i])>=(TH-eps-(1-Binary1[i])*M))
     m.addConstr((AQ[i]-Q[i])<=(TH-eps+(Binary1[i]*M)))
    0
  • Yi Ting Lin
    • Gurobi-versary
    • Conversationalist
    • Curious

    Hi Marika,

    I tried to change the sign of eps, but it would lead to both Binary4[2] and Binary4[3] =0.
    I want to have Binary4[2]=0 but Binary4[3]=1

    Is there any other way that might be able to solve this issue?

    Thanks for helping

    0
  • Marika Karbstein
    • Gurobi Staff

    I assume there is only one part for which AQ-Q <= TH < AQ holds. You need to have B1=1 if AQ-Q <= TH and B2=1 if TH < AQ. Then with Model.addGenConstrAnd() you can get B4=1 if both B1 and B2 are one. This should then only hold for 3 in your example. For 2 TH < AQ is not fulfilled.

    For i in range(1,5):
     m.addConstr((AQ[i]-Q[i])<=(TH + tol + (1-Binary1[i])*M))
     m.addConstr((AQ[i]-Q[i])>=(TH + tol - (Binary1[i]*M)))
     m.addConstr(TH +eps <= (AQ[i] + (1-Binary2[i])*M))
     m.addConstr(TH +eps >= (AQ[i] - (Binary2[i]*M)))
    
     m.addGenConstrAnd(Binary4[i], [Binary1[i],Binary2[i]])

    tol is a small tolerance, e.g. FeasibilityTol. But for the < check, eps needs to be a bigger value.

     

    0
  • Yi Ting Lin
    • Gurobi-versary
    • Conversationalist
    • Curious

    Hi Marika,

    Thanks for the reply. I'll check out how to use Model.addGenConstrAnd().

    Thanks again for your help.

     

    0

Post is closed for comments.