Skip to main content

Writing a complex constraint with multiple for and if conditions

Awaiting user input

Comments

2 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Maliheh Aramon
    • Gurobi Staff

    Hi Priyanka, 

    Do you want to implement the constraint below?

    \[\mbox{if} ~~ \sum_{l} a_{k, l, T_j} \geq 1 \rightarrow \sum_{l, m} q_{l,k,m,T_i} \leq c_k \sum_{l} a_{k, l, T_j}, ~~ \forall k, j, i ~(i \geq j)\]

    Since the indicator variable in the signature of the Model.addGenConstrIndicator() method should be a binary variable, you can define auxiliary binary variables \(z_{k,j}\) to implement the above constraint using one additional intermediate constraint as below:

    \[\mbox{if} ~~ \sum_{l} a_{k, l, T_j} \geq 1 \rightarrow z_{k,j} = 1, ~~ \forall k, j\]

    \[\mbox{if} ~~ z_{k,j} = 1 \rightarrow \sum_{l, m} q_{l,k,m,T_i} \leq c_k \sum_{l} a_{k, l, T_j}, ~~ \forall k, j, i ~(i \geq j)\]

    The second constraint matches the signature of the Model.addGenConstrIndicator() method where the indicator variable \(z_{k,j}\) is binary and it can be directly implemented. 

    The first constraint is logically equivalent to its contrapositive:

    \[\mbox{if} ~~ z_{k,j} \neq 1 \rightarrow  \sum_{l} a_{k, l, T_j} \ngeq 1  ~~ \forall k, j\]

    which can be written as below because the variables \(a\) are binaries. This constraint now matches the signature of the Model.addGenConstrIndicator() method and can be directly implemented.

    \[\mbox{if} ~~ z_{k,j} = 0 \rightarrow  \sum_{l} a_{k, l, T_j} = 0  ~~ \forall k, j\]

    For which constraint, did you get the error \(\texttt{Constraint has no bool value ...}\)?

    Best regards,

    Maliheh

    0

Post is closed for comments.