Skip to main content

turn on constraints only if a given condition is verified

Answered

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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Gabi,

    One way would be to introduce an additional binary variable \(y\) and add the following two constraints

    \[\begin{align}
    \sum_{i \in V_1} b_i &\geq 50y\\
    \sum_{i \in V_1} b_i &\leq 49+y\\
    b_i \in &\{0,1\} \, i \in V_1,\, y \in \{0,1\}
    \end{align}\]

    This way, if the sum of binaries over the set \(V_1\) equals 50, i.e., \(\sum_{i \in V_1} b_i = 50\), then \(y=1\). But if \(\sum_{i \in V_1} b_i < 50\), then \(y = 0\). You can then use the binary variable \(y\) and indicator constraints to enforce \(C_2\) constraints only if \(y=1\), i.e.,

    \[ y = 1 \Rightarrow C_2 \text{ type constraint} \]

    Note that this only works because \(\sum_{i \in V_1} b_i \) cannot be greater than \(50\). This is just one option an there might be an easier way to achieve the above.

    Best regards,
    Jaromił

    0

Post is closed for comments.