Skip to main content

can i use an indicator Constraint with Min/Max Constraint in Gurobi?

Answered

Comments

3 comments

  • Official comment
    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?.
  • Tobias Achterberg
    Gurobi Staff Gurobi Staff

    The conclusion of an indicator constraint must be a linear constraint. But you can easily get around this by introducing another set of variables that are defined identically to `a`; let's call them `b`. Then you would write

    m.addConstrs((x[k,i,j] == 1) >> (a[k,j] == b[k,j]) for k in range(K) for i in range(V) for j in range(1,V) if i!=j)
    m.addConstrs(b[k,j] == max_((a[k,i] + 5), 15) for k in range(K) for i in range(V) for j in range(1,V) if i!=j)

     

    1
  • Mhd Adnan Almouazen Alayoubi
    Gurobi-versary
    First Comment
    First Question

    thank you for your help that was very helpful.
    after i worked with your suggestion, i end up getting the Error:

    TypeError: object of type 'gurobipy.LinExpr' has no len()

    after digging in the internet, i found that this Error was caused by the max_() function. I can only pass a list of variables as arguments for this function and not a LinExpr as i do.

    (thanks to Robert Luce for his answer on google group https://groups.google.com/forum/#!topic/gurobi/oO3d2ItJiqs )

    thank you again for your help Tobias Achterberg

    0

Post is closed for comments.