Some problem about adding indicator constraints

Comments

2 comments

  • Eli Towle

    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
    Comment actions Permalink
  • hongyan liu

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

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk