Skip to main content

Some problem about adding indicator constraints

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • 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?.
  • Eli Towle
    • Gurobi Staff

    Hi Hongyan,

    First, note that < (strict inequality) is not supported for constraints. Perhaps you mean to use <= ( \( \leq \) )?

    Second, indicator constraints should be used when you want to say something like "if a binary variable is equal to 1, then this constraint should be enforced." In this case, dep isn't a variable in the model, but rather a list of values. If you only want to add constraints corresponding to the nonzero values in dep, you could instead include an if condition in your loop:

    m.addConstrs((z[0, j] <= z[0, i]) for i in range(tab_cnt - 1) for j in range(i + 1, tab_cnt) if dep[i][j] == 1)

    I hope this helps. Thanks!

    Eli

    0
  • hongyan liu
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you very much for your help, it really works.

    0

Post is closed for comments.